ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreASP 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:
Dell PowerEdge Servers
  #1  
Old August 20th, 2003, 08:27 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 and validation of check boxes

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, 01:01 PM
aspman aspman is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: Ashburn,VA
Posts: 105 aspman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 22 m 40 sec
Reputation Power: 5
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:

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

%>




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

%>

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > displaying and validation of check boxes


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

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

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





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