Help with JavaScript coding

?moddedu

Thread Junky
Joined
Nov 23, 2008
Messages
885
I'm currently stuck on a page I am making that uses JavaScript.

Here is the code-


<html>
<head>
<title>Quiz Page #2 || It's Impossible</title>
</head>
<body>
<body bgcolor="black">
<font color="red" face="Verdana"<center><h1>The Unbeatable Quiz!</font></center></h1>
<br />
<!--Home--><left><a><a href="index.html"><img src="draft\home pic.jpg"></a></left>
<br />
<!--Start Quiz--><left></left>
<br />
<!--What is the test?--><left></left>
<br />
<!--Rate The Quiz--><left></left>

<center>
<font color="red"><b>Is your number less than 15?</b></font>
<form name="thirty_half">
<p><input type="radio" name="yesno" value="input_0" size=10><font color="Red"><b>Yes</b></font></p>
<p><input type="radio" name="yesno" value="input_1" size=10><font color="Red"><b>No</b></font></p>
<br />
<br />
<input type="button" value="Continue" onClick="check()">
<br />
<br />
</form>
<script type= text/javascript>
function check()
{
if(document.thirty_half.yesno[0].checked)
{
confirm("You are gonna lose!");
window.location = 'quiz3.html'
}
}
</script>
</body>
</html>

How do I make it so that if the user checks "No", presses continue and then the page switches to another one? I can only do this for one option at a time (which currently the Yes option is the only one that works.
 
Code:
function check() {

  if(document.thirty_half.yesno[0].checked) {
    confirm("You are gonna lose!");
    window.location = 'quiz3.html'
    }
    
  if(document.thirty_half.yesno[1].checked) {
    confirm("You are gonna win!");
    window.location = 'quiz3.html'
  }
}

hope that helps :)
 
Last edited:
It's been a long time since I messed with it, but can both buttons have the same name?
 
Yes, radio buttons need to have the same name, otherwise they're like check boxes. If they have the same name, you can only select one out of that group. Make sense?
 
Code:
function check() {

  if(document.thirty_half.yesno[0].checked) {
    confirm("You are gonna lose!");
    window.location = 'quiz3.html'
    }
    
  if(document.thirty_half.yesno[1].checked) {
    confirm("You are gonna win!");
    window.location = 'quiz3.html'
  }
}

hope that helps :)
Thanks I'll see if that works.
 
I'm currently stuck on a page I am making that uses JavaScript.

Here is the code-


<html>
<head>
<title>Quiz Page #2 || It's Impossible</title>
</head>
<body>
<body bgcolor="black">
<font color="red" face="Verdana"<center><h1>The Unbeatable Quiz!</font></center></h1>
<br />
<!--Home--><left><a><a href="index.html"><img src="drafthome pic.jpg"></a></left>
<br />
<!--Start Quiz--><left></left>
<br />
<!--What is the test?--><left></left>
<br />
<!--Rate The Quiz--><left></left>

<center>
<font color="red"><b>Is your number less than 15?</b></font>
<form name="thirty_half">
<p><input type="radio" name="yesno" value="input_0" size=10><font color="Red"><b>Yes</b></font></p>
<p><input type="radio" name="yesno" value="input_1" size=10><font color="Red"><b>No</b></font></p>
<br />
<br />
<input type="button" value="Continue" onClick="check()">
<br />
<br />
</form>
<script type= text/javascript>
function check()
{
if(document.thirty_half.yesno[0].checked)
{
confirm("You are gonna lose!");
window.location = 'quiz3.html'
}
}
</script>
</body>
</html>

How do I make it so that if the user checks "No", presses continue and then the page switches to another one? I can only do this for one option at a time (which currently the Yes option is the only one that works.

Just do what you did with the "You're gonna lose.".......
 
Yes, radio buttons need to have the same name, otherwise they're like check boxes. If they have the same name, you can only select one out of that group. Make sense?

Yep, like I said - it's been a long time! Thanks.
 

Latest posts

Back
Top