Monday, November 29, 2010

Form field show/hide via JS

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.

Solution:

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

Like:

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=""

No comments: