|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
hi
im trying to display data from a access database, certain fields.. no problem there, after displaying this data im trying to give the user a choice, 2 radio buttons, with the vaules yes and no, a kind of multiple choice, but dynamically diplaying the questions from the database the problem comes when it dispalys on the screen, im only able to click one radio button , i only want 1 radio button per questions.....how do i do this....if i try to add any validation then the calculations i have set up to work out the correct number of ans doesnt work....????? code listed below <script Language="JavaScript" > var numQues = 22; var numChoi = 2; var answers = new Array(2); answers[0] = "right"; answers[1] = "right"; answers[2] = "right"; answers[3] = "right"; answers[4] = "right"; answers[5] = "right"; answers[6] = "right"; answers[7] = "right"; answers[8] = "right"; answers[9] = "right"; answers[10] = "right"; answers[11] = "right"; answers[12] = "right"; answers[13] = "right"; answers[14] = "right"; answers[15] = "right"; answers[16] = "right"; answers[17] = "right"; answers[18] = "right"; answers[19] = "right"; answers[20] = "right"; answers[21] = "right"; answers[22] = "right"; function getScore(form) { var score = 0; var currElt; var currSelection; for (i=0; i<numQues; i++) { currElt = i*numChoi; for (j=0; j<numChoi; j++) { currSelection = form.elements[currElt + j]; if (currSelection.checked) { if (currSelection.value == answers[i]) { score++; break; } } } } score = Math.round(score/numQues*100); form.percentage.value = score + "%"; var correctAnswers = ""; for (i=1; i<=numQues; i++) { correctAnswers += i + ". " + answers[i-1] + "\r\n"; } form.solutions.value = correctAnswers; } // --> </script> <form name="quiz"> <p> 1. <% DIM iRecordCount iRecordCount = 0 dim try try = iRecordCount DO WHILE NOT objRS.EOF %> <% = objRs.Fields("job") %> <br> <form name="quiz" method="post"> <input type="radio" name="q1" value="right"> Yes<br> <input type="radio" name="q1" value="wrong"> NO<br> <% iRecordCount = iRecordCount + 1 objRS.MoveNext Loop %> <input type="button" value="Get score" onClick="getScore(this.form)"> <input type="reset" value="Clear"> <p> Score = <input type=text size=15 name="percentage"> <br> Correct answers:<br> <textarea name="solutions" wrap="virtual" rows="4" cols="40"></textarea> </p> </form> help pls..... |
|
#2
|
|||
|
|||
|
Sorry to say this, but your code is a little jumbled up.
You have multiple form tags with the same name. Thats because,you have your form tag inside the loop. which you should not. you should have before the <%do while loop%> and since the radio button tag is also in the loop, you will have a bunch of radio buttons with the same name q1. That is the reason you are able to choose only one. Since the whole list forms a single group. Quote:
you need to have the name of the radio button as <input type="radio" name=q<%=irecordcount%> value="right"> <input type="radio" name=q<%=irecordcount%> value="wrong"> which would look like this on the screen <input type="radio" name=q1 value="right"> <input type="radio" name=q1 value="wrong"> <input type="radio" name=q2 value="right"> <input type="radio" name=q2 value="wrong"> etc. remember to set try to 1 or recordcount to 1 else the field values start from "q0" your code should look something like this <form name="quiz" method="post"> <% DO WHILE NOT objRS.EOF %> <% = objRs.Fields("job") %> <br> <input type="radio" name="q<%=irecordcount%>" value="right"> Yes<br> <input type="radio" name="q<%irecordcount%>" value="wrong"> NO<br> <% iRecordCount = iRecordCount + 1 objRS.MoveNext Loop %> |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > displaying and validation of check boxes |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|