Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 20th, 2003, 08:34 AM
zmalik zmalik is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 6 zmalik User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy displaying radio button validation

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.....

Reply With Quote
  #2  
Old August 20th, 2003, 10:12 AM
nopoints nopoints is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Windsor ON, Canada
Posts: 459 nopoints User rank is Corporal (100 - 500 Reputation Level)nopoints User rank is Corporal (100 - 500 Reputation Level)nopoints User rank is Corporal (100 - 500 Reputation Level)nopoints User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 13 h 44 m 22 sec
Reputation Power: 8
Code:
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 
%>

you need to give the radio buttons different names. the right/wrong should have the same name but the other set should be different. that way you end up with q0 right/wrong, q1 right/wrong, etc.
__________________
Programmer's Corner

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > displaying radio button validation


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway