Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Radio Button and Text Box 1

Status
Not open for further replies.

aarushi2001

Technical User
Nov 16, 2005
109
US
Hi Guys,

I have a question. I have a form, where user has to tick off 'yes' or 'no'. If a user ticks off 'yes' he is required to fill out text box 1 and if he ticks off 'no' he is required to fill out text box 2.

How can we add this feature?
 
So far I just have basic form validation code. I really dont know know how to do above feature :(..
 
in your form validation code, do something like this:

if radiobutton1 is checked
validate textbox1
else if radiobutton2 is checked
validate textbox2


note: that is not real javascript. please show what you have so far (javascript and HTML form) so we can be of some meaningful help.



*cLFlaVA
----------------------------
[tt]mr. pibb + red vines = crazy delicious![/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Hi clFlava,

Thanks for helping me out. I finally figured what I have to do. For If then thing this is the code I wrote:

function validate_form ( )
{
valid = true;

if ( ( document.contact_form.gender[0].checked == false ) && ( document.contact_form.gender[1].checked == false ) )
{
alert ( "Please choose your Gender: Male or Female" );
valid = false;
}

if (document.contact_form.gender[0].checked == true) {
if (document.contact_form.hello.value == "")
{
alert ("Please enter the hello field");
valid = false;
}
}
return valid;
}

I just need to integrate this script with my original script now. If it integration doesnt work I'll ask u clflava :)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top