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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Show form field if radio button checked

Status
Not open for further replies.

penguinspeaks

Technical User
Nov 13, 2002
234
US
Hello all, I hope you can help me with this.

In my form, I wish to show an additional field (paypal email address) only if the paypal radio button is checked.
I am aware that it would be an onclick event but with all of the class attributes that are on the form and each field, I do not even know where to start.

I tried to google it, but I did not see anything that explained clearly.

The code I have in the input is
Code:
<input name="payment_" type="radio" value="paypal" onclick="displayField();" />


Below is the html that would need to display if the above radio button is checked.
I just cannot understand what I need to do here.

Code:
<fieldset id="email_input" class="control-group" style="margin: 0px; padding: 0px; font-family: 'Open Sans', Arial, Helvetica, sans-serif; border: 0px;">
								<input id="email" class="fullspan default"  maxlength="50" name="paypalemail_" placeholder="Email" style="margin: 10px 0px; padding: 5px 40px 0px 10px; font-family: 'Open Sans', Arial, Helvetica, sans-serif; width: 252px; height: 50px; position: relative; font-size: 14px; color: rgb(82, 82, 82); outline: 0px; background: url('../images/text_field_bg.jpg') no-repeat; left: 0px; top: 0px;" type="text"  /><span class="email-suggestion-container" style="display: block;"></span><span style="display: block; font-size: 11px; margin-left: 5px; color: rgb(142, 142, 142); margin-top: -7px;">What 
								is your Paypal Email?</span></fieldset>

Any help or guidance would be greatly appreciated
 
set the visibility property of the element using the onClick event of the radio button

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Basically change either the display or visibility property of the element you wish to hide when the radio button is checked. You can even test the radio buttons sate and act accordingly.
In pseudo code:
Code:
function displayField()
{
var checkbox = getCheckbox;
var element getElementtoshow;
if(checkbox.checked)
{
[indent]element.style.display='block'; / element.style.visiblity='visible';[/indent]
}
else
{
[indent]element.style.display='none'; / element.style.visiblity='hidden';[/indent]
}

}


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
I now have it working thanks to your help. One of my issues was the fact that I was putting the <div> in the wrong place, thus cutting off the image and other choice.

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top