Hi all, I just started using JavaScript (as in, today) and I need some help.... Apologies, if this long-winded....
I've figured out how to show/hide form elements based on radio button selections, but am confused.
I have two form questions, the responses to which should pull up two different sections, but they should both display if the answers to each question is yes. The problem I'm having is that it will only display the section based on the most recent response.
For example:
If the user selects both "Love Juice" and "Love Milk" both the "JuiceFan" and "MilkFan" divs should display. If I select "Love Juice" the JuiceFan div displays, as it should, but then if I select "Love Milk" the MilkFan div displays but the JuiceFan div disappears. How can I make sure they both display?
Here is the script:
I've figured out how to show/hide form elements based on radio button selections, but am confused.
I have two form questions, the responses to which should pull up two different sections, but they should both display if the answers to each question is yes. The problem I'm having is that it will only display the section based on the most recent response.
For example:
Code:
// This question should display the JuiceFan div
Do you like juice?
<input type="radio" name="gd_set_9" value="Love Juice" onClick="hideAll();
changeDiv('JuiceFan','block');">Love Juice<br />
<input type="radio" name="gd_set_9" value="Hate Juice" onClick="hideAll();">Hate Juice<br />
// This question should display the MilkFan div
Do you like milk?
<input type="radio" name="gd_set_9" value="Love Milk" onClick="hideAll();
changeDiv('MilkFan','block');">Love Milk<br />
<input type="radio" name="gd_set_9" value="Hate Milk" onClick="hideAll();">Hate Milk<br />
If the user selects both "Love Juice" and "Love Milk" both the "JuiceFan" and "MilkFan" divs should display. If I select "Love Juice" the JuiceFan div displays, as it should, but then if I select "Love Milk" the MilkFan div displays but the JuiceFan div disappears. How can I make sure they both display?
Here is the script:
Code:
<script type="text/javascript">
<!--
function changeDiv(the_div,the_change)
{
var the_style = getStyleObject(the_div);
if (the_style != false)
{
the_style.display = the_change;
}
}
function hideAll()
{
changeDiv("JuiceFan","none");
changeDiv("MilkFan","none");
}
function getStyleObject(objectId) {
if (document.getElementById && document.getElementById(objectId)) {
return document.getElementById(objectId).style;
} else if (document.all && document.all(objectId)) {
return document.all(objectId).style;
} else {
return false;
}
}
// -->
</script>