Ask your JavaScript questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Form field addition via JS JavaScript


I'm working on an online credit app for a client and need to be able to add additional fields from a selected radio button.

Ex: There is a radio group that has two options, one is "Business" one is "Individual"
If someone clicks on Business, a text field for DBA needs to appear, If Individual is selected, DBA needs to be hidden.

Answers (1)


Damian Martinelli answers:

You need to set a onclick for each input radio to show or hide the additional input text.


<input type="radio" name="type" value="Business" onclick="document.getElementById('dba').style.display='block';" />
<input type="radio" name="type" value="Individual" onclick="document.getElementById('dba').style.display='none';" />
<input type="text" name="dba" id="dba" value="" />

Jeff Peak comments:

Awesome! Thanks a bunch!