Rexdreamer
asked on
popUp answer problem
Hi.
I am having problems with a quiz- answer popUp that should display " Sorry, that is incorrect" if it is false or "correct" if true. The pop ups are working fine it says what its supposed to but also adds the word false to the false statements and true to the true statements.
Not sure what I have done wrong.
Thanks in advance.
Not sure how of the code you need to decipher and i hope i am not doing this wrong.
I am having problems with a quiz- answer popUp that should display " Sorry, that is incorrect" if it is false or "correct" if true. The pop ups are working fine it says what its supposed to but also adds the word false to the false statements and true to the true statements.
Not sure what I have done wrong.
Thanks in advance.
Not sure how of the code you need to decipher and i hope i am not doing this wrong.
<html>
<head>
<!--
New Perspectives on JavaScript
Tutorial 6
Review Assignment
iMusicHistory Quiz 2
Author: Rexdreamer
Date: 08/29/09
Filename: quiz2.htm
Supporting files: lvb.gif, dotclear.gif, header.gif, main.css, quiz2.gif
-->
<title>iMusicHistory Quiz 2</title>
<link href="main.css" rel="stylesheet" type="text/css" title="General" />
<script type ="text/javascript">
function answer(correct){
popWin=window.open("","","left=250,screenX=250,top=250,screenY=250,width=200,height=200");
notPop=(popWin==null || typeof(popWin)=="undefined")? true:false;
if (notPop){
if (correct){
alert(choice + "Correct!");
} else {
alert(choice + "Sorry, that is incorrect");
}
}else{
writeContent(popWin,correct);
}
}
function writeContent(windowObj,correct) {
content="<html><head><title>Answer</title>";
content+="<link rel='stylesheet' href='quiz2.css' type='text/css' />";
if (correct) {
content+=correct + " Correct!";
} else {
content+=correct + " Sorry, that is incorrect";
}
content+="<br /><input type='button' value='OK' onclick='self.close()' />";
content+="</p></body></html>";
windowObj.document.write(content);
windowObj.document.close();
}
</script>
</head>
<body bgcolor="white"><a name="top"></a>
<!-- top of page logo and table -->
<div align="center">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="4" bgcolor="#99CC99" colspan="2" class="linegreen">
<img src="dotclear.gif" border="0" /></td>
</tr>
<tr>
<td height="2" bgcolor="#336699" colspan="2" class="lineblue">
<img src="dotclear.gif" border="0" /></td>
</tr>
<tr>
<td valign="middle" align="left" width="301" class="main" bgcolor="#336699"
rowspan="1">
<b><a class="main1" href="default.htm">
<img src="header.gif" hspace="4" vspace="0" border="0" align="left"
title="imusichistory interactive" alt="imusichistory interactive" />
</a></b></td>
<td align="right" valign="middle" bgcolor="#336699"><b>
<a class="main1" name="Beethoven"><img src="lvb.gif" width="53"
height="72" border="0" hspace="4" vspace="0" /></a></b></td>
</tr>
<tr>
<td height="4" bgcolor="#336699" class="lineblue" colspan="2">
<img src="dotclear.gif" width="500" height="4" border="0" /></td>
</tr>
<tr><td height="3" bgcolor="#99CC99" class="linegreen" colspan="2">
<img src="dotclear.gif" width="500" height="3" border="0" /></td>
</tr>
</table>
<!-- end of page logo and table -->
<!-- begin main content table -->
<table width="100%" border="0" cellspacing="0" cellpadding="2"
bgcolor="#336699">
<tr>
<td valign="top">
<table width="100%" border="0" cellspacing="1" cellpadding="10">
<tr>
<td bgcolor="white" class="body" valign="top" colspan="2" align="center">
<h2>Study Quiz 2</h2></td>
</tr>
<tr>
<td bgcolor="white" width="100%" valign="top" colspan="2">
<p class="quiz">The following is a sample of our upcoming study quizzes.
None of the scores is recorded for the study quizzes since they are
designed as study aids only. Full quizzes with scoring and results
will also be available.</p>
<form>
<dl class="form"><dt class="form">
<!-- Begin Question 1 -->
1. The modern system of musical notation is based on the notation developed in the 11th
century by:<br />
<input type="radio" name="Q1" onclick="answer(false)"/>
a) Guido d'Arezzo<br />
<input type="radio" name="Q1" onclick="answer(false)" />
b) Jacob Obrecht<br />
<input type="radio" name="Q1" onclick="answer(true)" />
c) Roland de Lassus<br />
<input type="radio" name="Q1" onclick="answer(false)" />
d) None of the above.<br /><br />
<!-- Begin Question 2 -->
2. The Baroque period occurs during the:<br />
<input type="radio" name="Q2" onclick="answer(false)" />
a) 12th and 13th century<br />
<input type="radio" name="Q2" onclick="answer(true)" />
b) 17th and 18th century<br />
<input type="radio" name="Q2" onclick="answer(false)" />
c) 19th and 20th century<br />
<input type="radio" name="Q2" onclick="answer(false)" />
d) None of the above.<br /><br />
<!-- Begin Question 3 -->
3. The fugue is a musical form associated with:<br />
<input type="radio" name="Q3" onclick="answer(false)" />
a) Mozart<br />
<input type="radio" name="Q3" onclick="answer(false)" />
b) Beethoven<br />
<input type="radio" name="Q3" onclick="answer(true)" />
c) Bach<br />
<input type="radio" name="Q3" onclick="answer(false)" />
d) None of the above.<br /><br />
<!-- Begin Question 4 -->
4. Allegro means:<br />
<input type="radio" name="Q4" onclick="answer(false)" />
a) Fairly slow<br />
<input type="radio" name="Q4" onclick="answer(true)" />
b) Quite fast, lively<br />
<input type="radio" name="Q4" onclick="answer(false)" />
c) with songlike interpretation<br />
<input type="radio" name="Q4" onclick="answer(false)" />
d) None of the above.<br /><br />
<!-- end of questions -->
</dt></dl>
</form>
<p><img src="dotclear.gif" width="500" height="1" border="0" /></p>
<!-- end of content -->
</td>
</tr>
<tr>
<td colspan="2" bgcolor="white" class="body">
<div align="center">
<table width="100%" border="0" cellspacing="3" cellpadding="0">
<tr>
<td bgcolor="white" class="body" align="right" nowrap="nowrap" valign="top">
<p><b>Go to Quiz: <a href="quiz.htm">1</a> - 2</b></p></td>
</tr>
<tr>
<td valign="top" align="center" class="bottom">
<b><i><a href="#top">To top</a></i></b></td>
</tr>
<tr>
<td class="body" valign="top"><b>iMusicHistory</b></td>
</tr>
<tr>
<td height="1" bgcolor="#000080" class="linenavy">
<img src="dotclear.gif" width="500" height="1" border="0" /></td>
</tr>
<!-- Begin navigation text cell -->
<tr>
<td valign="middle" bgcolor="#99CC99" align="center" class="nav">
<a class="nav" href="default.htm">Home</a> -
<a class="nav" href="lesson3.htm">Lessons</a> -
<a class="nav" href="quiz.htm">Quizzes</a> -
<a class="nav" href="terms.htm">Glossary</a><br />
<img src="dotclear.gif" width="500" height="2" border="0" /></td>
</tr>
<!-- End navigation text cell -->
<tr>
<td height="1" bgcolor="#000080" class="linenavy">
<img src="dotclear.gif" width="500" height="1" border="0" /></td>
</tr>
<tr>
<td align="center" class="bottom" nowrap="nowrap">
Contact: <a href="mailto:teresa@teresajenner.com">Teresa Jenner</a>,
Ph.D., 123 March Lane, San Rafael, CA 12345</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</body>
</html>
ASKER
Should that be changed to writeContent(popWin); or writeContent(correct);
It is called here in this section
[code]
1. The modern system of musical notation is based on the notation developed in the 11th
century by:<br />
<input type="radio" name="Q1" onclick="answer(false)"/>
a) Guido d'Arezzo<br />
<input type="radio" name="Q1" onclick="answer(false)" />
b) Jacob Obrecht<br />
<input type="radio" name="Q1" onclick="answer(true)" />
c) Roland de Lassus<br />
<input type="radio" name="Q1" onclick="answer(false)" />
d) None of the above.<br /><br />
[/code]
It is called here in this section
[code]
1. The modern system of musical notation is based on the notation developed in the 11th
century by:<br />
<input type="radio" name="Q1" onclick="answer(false)"/>
a) Guido d'Arezzo<br />
<input type="radio" name="Q1" onclick="answer(false)" />
b) Jacob Obrecht<br />
<input type="radio" name="Q1" onclick="answer(true)" />
c) Roland de Lassus<br />
<input type="radio" name="Q1" onclick="answer(false)" />
d) None of the above.<br /><br />
[/code]
what is choice here?
alert(choice + "Correct!");
alert(choice + "Correct!");
maybe you should use, line 37-40
if (correct) {
content+="Your choice is Correct!";
} else {
content+="Sorry, that is incorrect";
}
if (correct) {
content+="Your choice is Correct!";
} else {
content+="Sorry, that is incorrect";
}
or use this
<input type="radio" name="Q1" onclick="answer('a', false)"/> a) Guido d'Arezzo<br />
function answer(choice , correct){
popWin=window.open("",""," left=250,s creenX=250 ,top=250,s creenY=250 ,width=200 ,height=20 0");
notPop=(popWin==null || typeof(popWin)=="undefined ")? true:false;
if (notPop){
if (correct){
alert(choice + "Correct!");
} else {
alert(choice + "Sorry, that is incorrect");
}
}else{
writeContent(popWin, choice, correct);
}
}
function writeContent(windowObj, choice, correct) {
content="<html><head><titl e>Answer</ title>";
content+="<link rel='stylesheet' href='quiz2.css' type='text/css' />";
if (correct) {
content+=choice + " is correct!";
} else {
content+="Sorry, " + choice + " is incorrect";
}
content+="<br /><input type='button' value='OK' onclick='self.close()' />";
content+="</p></body></htm l>";
windowObj.document.write(c ontent);
windowObj.document.close() ;
}
<input type="radio" name="Q1" onclick="answer('a', false)"/> a) Guido d'Arezzo<br />
function answer(choice , correct){
popWin=window.open("","","
notPop=(popWin==null || typeof(popWin)=="undefined
if (notPop){
if (correct){
alert(choice + "Correct!");
} else {
alert(choice + "Sorry, that is incorrect");
}
}else{
writeContent(popWin, choice, correct);
}
}
function writeContent(windowObj, choice, correct) {
content="<html><head><titl
content+="<link rel='stylesheet' href='quiz2.css' type='text/css' />";
if (correct) {
content+=choice + " is correct!";
} else {
content+="Sorry, " + choice + " is incorrect";
}
content+="<br /><input type='button' value='OK' onclick='self.close()' />";
content+="</p></body></htm
windowObj.document.write(c
windowObj.document.close()
}
ASKER
Confused. Sorry, removed the "choice" from above.
still when you select your answer the popUp displays depending on answer....false sorry that is incorrect or true your choice is correct
still when you select your answer the popUp displays depending on answer....false sorry that is incorrect or true your choice is correct
ASKER
It stated that the answer function should only have 1 parameter = correct
function answer( correct){
popWin=window.open
function answer( correct){
popWin=window.open
here full code...
you are not passing the choice...
you are not passing the choice...
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Q_24696698.aspx.vb" Inherits="Q_24696698" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
1. The modern system of musical notation is based on the notation developed in the 11th
century by:<br />
<input type="radio" name="Q1" onclick="answer('a', false)" />
a) Guido d'Arezzo<br />
<input type="radio" name="Q1" onclick="answer('b', false)" />
b) Jacob Obrecht<br />
<input type="radio" name="Q1" onclick="answer('c', true)" />
c) Roland de Lassus<br />
<input type="radio" name="Q1" onclick="answer('d', false)" />
d) None of the above.<br /><br />
</div>
</form>
</body>
</html>
<script type="text/javascript">
function answer(choice, correct){
popWin=window.open("","","left=250,screenX=250,top=250,screenY=250,width=200,height=200");
notPop=(popWin==null || typeof(popWin)=="undefined")? true:false;
if (notPop){
if (correct){
alert(choice + "Correct!");
} else {
alert(choice + "Sorry, that is incorrect");
}
}else{
writeContent(popWin, choice, correct);
}
}
function writeContent(windowObj, choice, correct) {
content="<html><head><title>Answer</title>";
content+="<link rel='stylesheet' href='quiz2.css' type='text/css' />";
if (correct) {
content+=choice + " is correct!";
} else {
content+="Sorry, " + choice + " is incorrect";
}
content+="<br /><input type='button' value='OK' onclick='self.close()' />";
content+="</p></body></html>";
windowObj.document.write(content);
windowObj.document.close();
}
</script>
ASKER
maybe im confused, explain for me.
I was told to create a function called answer(); and it had to have 1 parameter named correct.
Is this not correct?
function answer(correct){
I was told to create a function called answer(); and it had to have 1 parameter named correct.
Is this not correct?
function answer(correct){
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect that got rid of the extra true false added to my popup wording but now it shows them all as being false the wrong answer
ASKER
Found it... when we changed to single parameter we didnt remove the call to the 2nd parameter.
function answer(correct){
function writeContent(windowObj, choice, correct) {
function answer(correct){
function writeContent(windowObj, choice, correct) {
:)
ASKER
Thanks alot..Have a great night..
ASKER
Think i hit the wrong button on this. did i?
Open in new window