Hi, i am writing a questionnaire in javascript to which I want to create questions that are dependent upon each other, and so are only displayed according to how a user answers a particular question. question 1 reads like this...

<div class="start" id="main">
<form name="eBayform">
<h3>1) Do you have a buyer/seller account registered with eBay?</h3>
<table class="center">
<tr>
<td><input type="radio" name="account" value="buyer" onClick="onchangeQu1('both');" />
Buyer</td>
<td><input type="radio" name="account" value="seller" onClick="onchangeQu1('both');" /> Seller</td>
<td><input type="radio" name="account" value="both" onClick="onchangeQu1('both');" /> Both</td>
<td><input type="radio" name="account" value="neither" onClick="onchangeQu1('neither');" />
Neither</td>
</tr>
</table>
</form>
</div>

and the function it calls...

function onchangeQu1(theRadio, theObjectId)
{
theObject = document.getElementById(theObjectId);
if(theRadio.checked){
//Remove all.
for(i=0; i<qu1.length; i++){
document.getElementById(qu1).style.display = "none";
}
//Display correct one
theObject.style.display='block';
}
else{
theObject.style.display='none';

}
}

This allows the user to see the first few questions which is fine. However when the user comes to qu12 they are asked certain questions depending on whether they are buyers or sellers. As this is established in qu 1 would the best idea be to create a function that is called in the function onchnageQu1 that says something like, if radio checked equals buyer then display qu 12 etc..? I am not quite sure how to do this?

Thanks

radio buttons are referenced like an array so you probably want something like

if(document.eBayform.account[0].checked)
//do buyer stuff
else if(document.eBayform.account[1].checked)
//do seller stuff
else if(document.eBayform.account[2].checked)
//do both stuff
else if(document.eBayform.account[3].checked)
//do neither

is that what you are looking for?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.