April 21st, 2010, 07:34 PM
Conditional form field
I want to create a form that has a conditional question, but cannot find anything anywhere to help.
Do you () drive to work () use public transportation
If the answer is "use public transportation", I want to display another radio button question
Do you primarily use the
() train () bus () other
Can anyone assist?
April 21st, 2010, 10:23 PM
The easiest way would be to have the ()train ()bus ()other in a hidden div, and when "use public transportation" is checked to unhide it
Originally Posted by siric
so hidden div is something like
and then in your "use public transporation" button you have an onclick event to a function that would do something like
<div id="transContain" style="display:none;">
<input type="radio" id="train" value="train"/>
document.getElementById("transContain").style.display = "block";
Comments on this post
April 22nd, 2010, 04:18 AM
Eeer... not really. A "hidden" form element, on using CSS visibility or display, remains in the the DOM tree, thus the form will still send its value, if any, on submit. In other words if you make an element "hidden" that will not make it "disabled" as well.
Originally Posted by Dameon51
Either you disable/enable that element whenever you make it disappear/appear, or you use DOM methods to create/append/remove that element (createElement(), appendChild(), removeChild()... and so on)
April 22nd, 2010, 08:11 AM
Well sending those additional fields shouldn't be much of a problem because you can just ignore them.
- Hugh of Borg
The first thing young borg are taught: Keep away from Microsoft software!
April 22nd, 2010, 10:01 AM
If the user doesn't check anything though the value submitted will be blank. Yeah you'll probably want to put some more conditions in there, like unchecking the checked value if that div hides again, but a blank submit is should good enough, depending on whats going on server side.
Originally Posted by KorRedDevil
April 22nd, 2010, 06:14 PM
Thanks everyone. Got it going and yes, I will just ignore the variables that I don't need.