|
-
Sep 19th, 2009, 11:19 AM
#1
Thread Starter
New Member
help me please about vbscript radio quiz
A webpage would ask the name of
the exam taker before he gonna take the exam.
He/she can not take the exam unless he/she will
input his/her name. If the name is given,
he/she can now take the exam; after which,
he/she can now submit his/her answers then the
program will automatically check it. On the
message box, the name of the exam taker will appear,
the number of correct items and his/her average.
PLEASE TNX...
I NEED A CODE
-
Sep 19th, 2009, 12:15 PM
#2
Re: help me please about vbscript radio quiz
Try something like this:
(not tested code)
Code:
<html>
<head runat="server">
<title>Untitled Page</title>
<script language="vbscript" type="text/vbscript" >
Sub btnSubmit_Click()
If Trim(form1.TextBox1.value) ="" Then
MsgBox "Please enter your name."
Exit Sub
End If
form1.submit()
End Sub
</script>
</head>
<body>
<form id="form1" action="MyPage.asp">
<div>
<input type="text" id="TextBox1" name="TextBox1" />
<input type="button" name="btnSubmit" value="Submit" onclick="btnSubmit_Click" />
</div>
</form>
</body>
</html>
Also be aware that you are using vbscript which is not supported by all browsers. Internet Explorer supports it for sure. So it will work on Internet Explorer and compatible browsers only.
-
Sep 19th, 2009, 12:30 PM
#3
Thread Starter
New Member
Re: help me please about vbscript radio quiz
thankz for the help sir..
how about a quiz that needs to answer using radio..
just 5 example question and automatically check the answer if the submit button is click..
tnx
-
Sep 19th, 2009, 01:30 PM
#4
Re: help me please about vbscript radio quiz
You can put 5 radio buttons (<input type="radio" >). Then on submit you will check in server side code whether it is the correct answer, either by connecting to database or file etc. Depends on where you have the correct answers stored.
-
Sep 19th, 2009, 09:26 PM
#5
Thread Starter
New Member
Re: help me please about vbscript radio quiz
can you give me a code sir?
please..i tried all my best but i cant get it..
a html that like a online quiz that has radio and have minimum of 5 question then if the submit button is clicked..theres a pop up says the name of the exam taker and the correct answers got .
please sir.
-
Sep 20th, 2009, 01:04 PM
#6
Re: help me please about vbscript radio quiz
No please.
We don't have a practice here of coding on the behalf of the programmer. We only help them to get through their problems they face while coding.
Instead of asking for code, it would be appreciated if you just try on your own and construct something. Show it here and we will be glad to help you with the problem you have with it.
-
Sep 20th, 2009, 01:11 PM
#7
Thread Starter
New Member
Re: help me please about vbscript radio quiz
OK HERE
Code:
<HTML>
<HEAD>
<TITLE> Gabriel's IQ Test </TITLE>
<style type="text/css">
body
{
background-image:url('http://dl.img.qj.net/uploads/files_module/screenshots/253_PSP-background-thor64.jpg');
background-repeat:no-repeat;
background-attachment:fixed;
background-position:center;
}
h1 {text-decoration:bold,underline}
h2 {text-decoration:underline}
h3 {text-decoration:underline}
h4 {text-decoration:blink}
</style>
<SCRIPT LANGUAGE="VBSCRIPT">
<!--
Option Explicit
Sub btnSubmit_Click()
dim name
name = document.form1.TextBox1.value
If Trim(form1.TextBox1.value) ="" Then
MsgBox "Please enter your name.",16
else
MsgBox "Hi " &name&"!! You may now take the quiz"
Exit Sub
End If
End Sub
Sub cmdSubmit_OnClick()
Dim i, strChoice1, strChoice2, strChoice3, strChoice4, strChoice5, name, total,average
dim choice1,choice2,choice3,choice4,choice5
name = document.form1.TextBox1.value
For i = 0 to window.frmData.number1.length-1
If window.frmData.number1(i).checked=True Then
strChoice1 = window.frmData.number1(i).Value & chr(13)
choice1 = 1
End If
next
For i = 0 to window.frmData.number2.length-1
If window.frmData.number2(i).checked=True Then
strChoice2 = window.frmData.number2(i).Value & chr(13)
choice2 = 1
End If
Next
For i = 0 to window.frmData.number3.length-1
If window.frmData.number3(i).checked=True Then
strChoice3 = window.frmData.number3(i).Value & chr(13)
choice3 = 1
End If
Next
For i = 0 to window.frmData.number4.length-1
If window.frmData.number4(i).checked=True Then
strChoice4 = window.frmData.number4(i).Value & chr(13)
choice4 = 1
End If
Next
For i = 0 to window.frmData.number5.length-1
If window.frmData.number5(i).checked=True Then
strChoice5 = window.frmData.number5(i).Value & chr(13)
choice5 = 1
End If
total = choice1 + choice2 + choice3 + choice4 + choice5
average = total/ 5*100
Next
if name = "" then
MsgBox "You should Enter your Name!!!",16
else
MsgBox " Hi "&name&" you're result is: "&total&chr(13)& chr(13) & strChoice1 & chr(13) & strChoice2 & chr(13) & strChoice3 & chr(13) & strChoice4 & chr(13) & strChoice5 & chr(13)& chr(13) &"Total average is: "& average
end if
End Sub
-->
</SCRIPT>
<SCRIPT LANGUAGE="VBSCRIPT">
sub gab1 ()
dim name
name = document.form1.TextBox1.value
if name="" then
msgbox "Ooppss! You must enter your name first!",16
end if
end sub
</script>
</HEAD>
<BODY >
<H1> <CENTER> IQ TEST </CENTER> </H1>
<center><img src="http://bryanking.net/wp-content/uploads/2009/03/intelligence_quotient_iq.jpg" width=200 height=200 border=4></center>
<H3> <CENTER> By: Gabriel </CENTER></H3>
<H4> <CENTER> (Intelligence Quotient Questions) </CENTER> </H4>
<form name=form1>
<font color="RED" face="PAPYRUS"><p align="center"><b>Enter you Name to Continue:</b> </font></br></br><input type="text" id="TextBox1" name="TextBox1" />
<input type="button" name="btnSubmit" value="Submit" onclick="btnSubmit_Click" /><INPUT TYPE=RESET>
</form>
<HR>
<font color="red">
<h2>QUESTIONS</h2>
<H4>1.)If you pass the 2nd person in a race what will You be coming?</p> </H4>
<FORM NAME=frmData>
<PRE>
<INPUT TYPE=RADIO NAME=number1 onclick="gab1" VALUE="1.) Wrong!" CHECKED> 1st
<INPUT TYPE=RADIO NAME=number1 onclick="gab1" VALUE="1.) Correct!(you should be the 2nd)"> 2nd
<INPUT TYPE=RADIO NAME=number1 onclick="gab1" VALUE="1.) Wrong!"> 3rd
<HR>
<H4>2.) Mary's father had 5 children:
Mama
Meme
Mimi
Momo
What was the 5th child's name? </H4>
<INPUT TYPE=RADIO NAME=number2 onclick="gab1" VALUE="2.) Wrong!" CHECKED> Mumu
<INPUT TYPE=RADIO NAME=number2 onclick="gab1" VALUE="2.) Correct!(Mary's Father)"> Mary
<INPUT TYPE=RADIO NAME=number2 onclick="gab1" VALUE="2.) Wrong! "> Marie
<HR>
<H4>3.) Some months have 30 days, some months have 31 days. How many months have 28 days?</H4>
<INPUT TYPE=RADIO NAME=number3 onclick="gab1" VALUE="3.) Wrong!" CHECKED> 2
<INPUT TYPE=RADIO NAME=number3 onclick="gab1" VALUE="3.) Wrong!"> 6
<INPUT TYPE=RADIO NAME=number3 onclick="gab1" VALUE="3.) Correct!(All, Every month has atleast 28 days)"> 12
<HR>
<H4>4.) If you had only one match and entered a COLD and DARK room, where there was an oil heater, an oil lamp and a candle,</br> which would you light first?</H4>
<INPUT TYPE=RADIO NAME=number4 onclick="gab1" VALUE="4.) Correct!(the match should be to light first)" CHECKED> The Match
<INPUT TYPE=RADIO NAME=number4 onclick="gab1" VALUE="4.) Wrong!"> Oil lamp
<INPUT TYPE=RADIO NAME=number4 onclick="gab1" VALUE="4.) Wrong"> Candle
<HR>
<H4>5.) How many animals of each species did Moses take with him in the Ark?</H4>
<INPUT TYPE=RADIO NAME=number5 onclick="gab1" VALUE="5.) Correct!(None. It was Noah, not Moses)" CHECKED> 0
<INPUT TYPE=RADIO NAME=number5 onclick="gab1" VALUE="5.) Wrong!"> 1
<INPUT TYPE=RADIO NAME=number5 onclick="gab1" VALUE="5.) Wrong!"> 2
<HR>
<p><INPUT TYPE=BUTTON VALUE="Check!" NAME="cmdSubmit"> <INPUT TYPE=RESET>
</PRE>
</FORM>
</BODY>
<HTML>
my problem is to get the number of correct items and his/her average.
and display it here
Code:
MsgBox " Hi "&name&" you're result is: "&total&chr(13)& chr(13) & strChoice1 & chr(13) & strChoice2 & chr(13) & strChoice3 & chr(13) & strChoice4 & chr(13) & strChoice5 & chr(13)& chr(13) &"Total average is: "& average
thankzzzzz
-
Sep 20th, 2009, 02:54 PM
#8
Re: help me please about vbscript radio quiz
See and correct the highlighted linges in your code. We need to conditionally set that value only if the correct answer was guessed.
Code:
Sub cmdSubmit_OnClick()
Dim i, strChoice1, strChoice2, strChoice3, strChoice4, strChoice5, name, total,average
dim choice1,choice2,choice3,choice4,choice5
name = document.form1.TextBox1.value
For i = 0 to window.frmData.number1.length-1
If window.frmData.number1(i).checked=True Then
strChoice1 = window.frmData.number1(i).Value & chr(13)
If instr(strChoice1,"Wrong!")=0 Then choice1 = 1
End If
next
For i = 0 to window.frmData.number2.length-1
If window.frmData.number2(i).checked=True Then
strChoice2 = window.frmData.number2(i).Value & chr(13)
If instr(strChoice2,"Wrong!")=0 Then choice2 = 1
End If
Next
For i = 0 to window.frmData.number3.length-1
If window.frmData.number3(i).checked=True Then
strChoice3 = window.frmData.number3(i).Value & chr(13)
If instr(strChoice3,"Wrong!")=0 Then choice3 = 1
End If
Next
For i = 0 to window.frmData.number4.length-1
If window.frmData.number4(i).checked=True Then
strChoice4 = window.frmData.number4(i).Value & chr(13)
If instr(strChoice4,"Wrong!")=0 Then choice4 = 1
End If
Next
For i = 0 to window.frmData.number5.length-1
If window.frmData.number5(i).checked=True Then
strChoice5 = window.frmData.number5(i).Value & chr(13)
If instr(strChoice5,"Wrong!")=0 Then choice5 = 1
End If
Next
total = choice1 + choice2 + choice3 + choice4 + choice5
average = total/ 5*100
if name = "" then
MsgBox "You should Enter your Name!!!",16
else
MsgBox " Hi "&name&" you're result is: "&total&chr(13)& chr(13) & strChoice1 & chr(13) & strChoice2 & chr(13) & strChoice3 & chr(13) & strChoice4 & chr(13) & strChoice5 & chr(13)& chr(13) &"Total average is: "& average
end if
End Sub
-
Sep 20th, 2009, 03:22 PM
#9
Re: help me please about vbscript radio quiz
Since you are repeating the loops, you can also reduce the code by putting it in a separate function.
e.g.
Code:
Sub cmdSubmit_OnClick()
Dim i, strChoice1, strChoice2, strChoice3, strChoice4, strChoice5, name, total,average
dim choice1,choice2,choice3,choice4,choice5
name = document.form1.TextBox1.value
strChoice1 = GetCheckedItem(window.frmData.number1)
strChoice2 = GetCheckedItem(window.frmData.number2)
strChoice3 = GetCheckedItem(window.frmData.number3)
strChoice4 = GetCheckedItem(window.frmData.number4)
strChoice5 = GetCheckedItem(window.frmData.number5)
If instr(strChoice1,"Wrong!")=0 Then choice1 = 1
If instr(strChoice2,"Wrong!")=0 Then choice2 = 1
If instr(strChoice3,"Wrong!")=0 Then choice3 = 1
If instr(strChoice4,"Wrong!")=0 Then choice4 = 1
If instr(strChoice5,"Wrong!")=0 Then choice5 = 1
total = choice1 + choice2 + choice3 + choice4 + choice5
average = total/ 5*100
if name = "" then
MsgBox "You should Enter your Name!!!",16
else
MsgBox " Hi "&name&" you're result is: "&total&chr(13)& chr(13) & strChoice1 & chr(13) & strChoice2 & chr(13) & strChoice3 & chr(13) & strChoice4 & chr(13) & strChoice5 & chr(13)& chr(13) &"Total average is: "& average
end if
End Sub
Function GetCheckedItem(theControl)
Dim i
For i = 0 to theControl.Length - 1
If theControl(i).Checked = True Then
GetCheckedItem = theControl(i).Value
Exit For
End If
Next
End Function
-
Sep 20th, 2009, 03:34 PM
#10
Re: help me please about vbscript radio quiz
Or still better using arrays:
Code:
Sub cmdSubmit_OnClick()
Dim i, name, total,average, strChoice(5)
strChoice(1) = GetCheckedItem(window.frmData.number1)
strChoice(2) = GetCheckedItem(window.frmData.number2)
strChoice(3) = GetCheckedItem(window.frmData.number3)
strChoice(4) = GetCheckedItem(window.frmData.number4)
strChoice(5) = GetCheckedItem(window.frmData.number5)
For i = 1 To 5
If instr(strChoice(i), "Wrong!") = 0 Then total = total + 1
Next
average = total/ 5*100
name = document.form1.TextBox1.value
If name = "" then
MsgBox "You should Enter your Name!!!",16
Else
MsgBox " Hi " & name & " you're result is: " & total & chr(13) & chr(13) & _
strChoice(1) & chr(13) & _
strChoice(2) & chr(13) & _
strChoice(3) & chr(13) & _
strChoice(4) & chr(13) & _
strChoice(5) & chr(13) & chr(13) & _
"Total average is: " & average
End If
End Sub
Function GetCheckedItem(theControl)
Dim i
For i = 0 to theControl.Length - 1
If theControl(i).Checked = True Then
GetCheckedItem = theControl(i).Value
Exit For
End If
Next
End Function
Last edited by Pradeep1210; Sep 20th, 2009 at 03:38 PM.
-
Sep 20th, 2009, 09:40 PM
#11
Thread Starter
New Member
-
Sep 21st, 2009, 06:18 AM
#12
Thread Starter
New Member
Re: help me please about vbscript radio quiz
sir i want to add comment on his/her average but where should i put this codes
Code:
if average = 0 then
MsgBox "Under 70 - Definite feeble-mindedness"
else if average = 20 then
MsgBox "80 - 90 - Dullness"
else if average = 40 then
MsgBox "90 - 109 - Normal or Average Intelligence"
else if average = 60 then
MsgBox "110 - 119 - Superior Intelligence"
else if average = 80 then
MsgBox "120 - 140 - Very Superior Intelligence"
else if average = 100 then
MsgBox "Over 140 - Genius or near genius"
-
Sep 21st, 2009, 06:54 AM
#13
Re: help me please about vbscript radio quiz
Code:
Sub cmdSubmit_OnClick()
Dim i, name, total,average, strChoice(5), result
strChoice(1) = GetCheckedItem(window.frmData.number1)
strChoice(2) = GetCheckedItem(window.frmData.number2)
strChoice(3) = GetCheckedItem(window.frmData.number3)
strChoice(4) = GetCheckedItem(window.frmData.number4)
strChoice(5) = GetCheckedItem(window.frmData.number5)
For i = 1 To 5
If instr(strChoice(i), "Wrong!") = 0 Then total = total + 1
Next
average = total/ 5*100
Select Case average
Case 0
result = "Under 70 - Definite feeble-mindedness"
Case <= 20
result = "80 - 90 - Dullness"
Case <= 40
result = "90 - 109 - Normal or Average Intelligence"
Case <= 60
result = "110 - 119 - Superior Intelligence"
Case <= 80
result = "120 - 140 - Very Superior Intelligence"
Case <= 100
result = "Over 140 - Genius or near genius"
End Select
name = document.form1.TextBox1.value
If name = "" then
MsgBox "You should Enter your Name!!!",16
Else
MsgBox " Hi " & name & " you're result is: " & total & chr(13) & chr(13) & _
strChoice(1) & chr(13) & _
strChoice(2) & chr(13) & _
strChoice(3) & chr(13) & _
strChoice(4) & chr(13) & _
strChoice(5) & chr(13) & chr(13) & _
"Total average is: " & average & chr(13) & _
"Result: " & result
End If
End Sub
Function GetCheckedItem(theControl)
Dim i
For i = 0 to theControl.Length - 1
If theControl(i).Checked = True Then
GetCheckedItem = theControl(i).Value
Exit For
End If
Next
End Function
-
Sep 21st, 2009, 07:01 AM
#14
Thread Starter
New Member
Re: help me please about vbscript radio quiz
can you do it in else if statement?..
please..thankzzzz
-
Sep 21st, 2009, 07:37 AM
#15
Re: help me please about vbscript radio quiz
When we have one variable and want to check it against multiple values, it is best to use Select..Case.
But anyways, you can use If..Else too. Here is how to do it:
Code:
Sub cmdSubmit_OnClick()
Dim i, name, total,average, strChoice(5), result
strChoice(1) = GetCheckedItem(window.frmData.number1)
strChoice(2) = GetCheckedItem(window.frmData.number2)
strChoice(3) = GetCheckedItem(window.frmData.number3)
strChoice(4) = GetCheckedItem(window.frmData.number4)
strChoice(5) = GetCheckedItem(window.frmData.number5)
For i = 1 To 5
If instr(strChoice(i), "Wrong!") = 0 Then total = total + 1
Next
average = total/ 5*100
If average = 0 then
result = "Under 70 - Definite feeble-mindedness"
else if average <= 20 then
result = "80 - 90 - Dullness"
else if average <= 40 then
result = "90 - 109 - Normal or Average Intelligence"
else if average <= 60 then
result = "110 - 119 - Superior Intelligence"
else if average <= 80 then
result = "120 - 140 - Very Superior Intelligence"
else if average <= 100 then
result = "Over 140 - Genius or near genius"
End If
name = document.form1.TextBox1.value
If name = "" then
MsgBox "You should Enter your Name!!!",16
Else
MsgBox " Hi " & name & " you're result is: " & total & chr(13) & chr(13) & _
strChoice(1) & chr(13) & _
strChoice(2) & chr(13) & _
strChoice(3) & chr(13) & _
strChoice(4) & chr(13) & _
strChoice(5) & chr(13) & chr(13) & _
"Total average is: " & average & chr(13) & _
"Result: " & result
End If
End Sub
Function GetCheckedItem(theControl)
Dim i
For i = 0 to theControl.Length - 1
If theControl(i).Checked = True Then
GetCheckedItem = theControl(i).Value
Exit For
End If
Next
End Function
-
Sep 23rd, 2009, 09:00 AM
#16
Thread Starter
New Member
-
Oct 3rd, 2009, 01:42 PM
#17
Re: help me please about vbscript radio quiz
Please try to keep one question per thread. Unless the question is an extension of the original topic etc.
So this last question would be best in the Office Development forum. Please post your question in that forum. Thanks
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|