PDA

View Full Version : Questionaire Checking...



vijay101
01-16-2008, 07:43 AM
Hi....

I have a simple questionaire for a website, and I need help with JS on it. There are 5 questions in all, and 2 options for each...more like a choose the correct answer....i am giving the code below...i need help in JS as to how to check for the correct answer. I tried it for one set, the first question, it worked, but I am unable to duplicate the same function for all 5.

I also don't know if this is the correct way.....

[HTML CODE BEGIN]
<tr>
<td height="25">Choose the Correct Answer </td>
</tr>
<tr>
<td height="25">Q1. I would like to buy this painting because </td>
</tr>
<tr>
<td height="25"><form name="q1form">
<p>
<input type="radio" name="q1"/>
It is cheaper than the others in the Market
<br />
<input type="radio" name="q1"/>
It captures my imagination and grows on me</p>
</form></td>
</tr>
<tr>
<td height="25">Q2. The person who paints the picture and the character of the artist makes no difference to the &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;painting</td>
</tr>
<tr>
<td height="25"><form name="q2form">
<input type="radio" name="q2" />
True<br />
<input type="radio" name="q2" />
False
<br />
</form></td>
</tr>
<tr>
<td height="25">Q2A. The painting is an extension of the artist's personality and life, and reflects on his attitude &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;towards God and man</td>
</tr>
<tr>
<td height="25"><form name="q3form">
<input type="radio" name="q3"/>
True
<br />
<input type="radio" name="q3" />
False
<br />
</form></td>
</tr>
<tr>
<td height="25">Q3. Paintngs are an Investment</td>
</tr>
<tr>
<td height="25"><form name="q4form">
<input type="radio" name="q4" />
True<br />
<input type="radio" name="q4" />
False<br />
</form></td>
</tr>
<tr>
<td height="25">Q3A. Copies and Immitations are the same as the original paintings and have the same effect. </td>
</tr>
<tr>
<td height="25"><form name="q5form">
<input type="radio" name="q5"/>
True<br />
<input type="radio" name="q5" />
False
<br />
</form></td>
</tr>
<tr>
<td height="25"><form name="form1" id="form1" method="post" action="">
<input type="submit" name="Submit" value="Submit" onclick="docheck();"/>
</form></td>
</tr>
</table>
[HTML CODE END]

This basically has a table, in which i have the 5 questions. The answersto the questions arein a form,so I have 4 forms....this where the problem is, maybe I have not laid the document correctly, can you please help ?

vijay101
01-16-2008, 03:51 PM
Hi,

This is still regarding my post on radio button checking. I have the form here with all the questions..I have it working to an extent, but not yet there....what is wrong with this code ?

<script language="javascript" type="text/javascript">
function docheck()
{
for(i=0;i < document.qform.a1.length;i++){
if(document.qform.a1[i].checked==true){
alert('You selected:' + document.qform.a1[i].value);
break;
}
else if(document.qform.a1[i].checked==false){
alert('Please answer the questionarie before proceeding.');
break;
}
}
}
</script>

I don't know if this is the best way, i have a for loop that checks for the 10 different radio buttons on my 5 questions. The funniest part is that if I comment the else if part of the code, the if condition works....otherwise the else if part fires everytime.

I added the else if part to have a second level check to ensure no one can continue without the completing the questionnaire.

vijay101
01-18-2008, 01:19 AM
Any replies to this ? please help me...

thanks
Vj