check the error

what is the error in my online examination program

Page 1 of 1

4 Replies - 689 Views - Last Post: 26 June 2010 - 02:35 PM

#1 srideviniveditha  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 26-June 10

check the error

Posted 26 June 2010 - 11:00 AM

i want to know what is the error in my online examination javascript program

<html>
<head>
<script language="javascript">
function ch()
{
if(((fr.q1.checked==true)&&(fr.q2.checked==true)&&(fr.q3.checked==true))||((fr.q1.checked==true)&&(fr.q2.checked==true))||((fr.q2.checked==true)&&(fr.q3.checked==true))||((fr.q1.checked==true)&&(fr.q3.checked==true)))
{
alert("please check any one ");
fr.t1.value="0";
}
else
if(((fr.q4.checked==true)&&(fr.q5.checked==true)&&fr.q6.checked==true))||((fr.q4.checked==true)&&(fr.q5.checked==true))||((fr.q5.checked==true)&&(fr.q6.checked==true))||((fr.q4.checked==true)&&(fr.q6.checked==true)))
{
alert("hi sweetie,u r supposed to check only one");
fr.t1.value="0";
}
else
if(((fr.q7.checked==true)&&(fr.q8.checked==true)&&fr.q9.checked==true))||((fr.q7.checked==true)&&(fr.q8.checked==true))||((fr.q8.checked==true)&&(fr.q9.checked==true))||((fr.q7.checked==true)&&(fr.q9.checked==true)))
{
alert("hi sweetie,u r supposed to check only one");
fr.t1.value="0";
}
else if((fr.q3.checked==true)&&(fr.q4.checked==true)&&(fr.q8.checked==true))
fr.t1.value="21";
else if((fr.q3.checked==true)&&(fr.q4.checked==true)&&(fr.q8.checked==false))
fr.t1.value="22";
else if((fr.q3.checked==true)&&(fr.q4.checked==false)&&(fr.q8.checked==true))
fr.t1.value="23";
else if((fr.q3.checked==false)&&(fr.q4.checked==true)&&(fr.q8.checked==true))
fr.t1.value="24";
else if((fr.q3.checked==false)&&(fr.q4.checked==false)&&(fr.q8.checked==true))
fr.t1.value="25";
else if((fr.q3.checked==false)&&(fr.q4.checked==true)&&(fr.q8.checked==false))
fr.t1.value="26";
else if((fr.q3.checked==true)&&(fr.q4.checked==false)&&(fr.q8.checked==false))
fr.t1.value="27";
else if((fr.q3.checked==false)&&(fr.q4.checked==false)&&(fr.q8.checked==false))
fr.t1.value="0";
}
function info()
{
if(fr.t1.value=="21")
{
alert("u'll be married at the age of 21");
}
else if(fr.t1.vale="22")
{
alert("at age22");
}
else if(fr.t1.vale="23")
{
alert("at age23");
}
else if(fr.t1.vale="24")
{
alert("at age24");
}
else if(fr.t1.vale="25")
{
alert("at age25");
}
else if(fr.t1.vale="26")
{
alert("at age26");
}
else if(fr.t1.vale="27")
{
alert("at age27");
}
else if(fr.t1.vale="0")
{
alert("at age28");
}
}
</script>
</head>
<body>
<form name=fr>
1.have u ever thought about marriage<br>
<p><input type=checkbox name=q1 value=s all d time>&nbspa.&nbsp s all d time
<br><input type=checkbox name=q2 value=dunno...>&nbspb.&nbsp dunno...
<br><input type=checkbox name=q3 value=yes....bt nt nw!!>&nbspc.&nbsp yes....bt nt nw!!
<p><br>
2.You Think Most Of Womens Getting Married With Guys Who's ?<br>

<p><input type=checkbox name=q1 value=powerful>&nbspa.&nbsp powerful
<br><input type=checkbox name=q2 value=smarter n funnier>&nbspb.&nbsp smarter n funnier
<br><input type=checkbox name=q3 value=richer>&nbspc.&nbsp richer<br>
<p>
3.Are You In love With Someone ?<br>
<p><input type=checkbox name=q1 value= never !!>&nbspa.&nbsp never !!
<br><input type=checkbox name=q2 value=yesssssssss !!>&nbspb.&nbsp yesssssssss !!
<br><input type=checkbox name=q3 value=maybe....>&nbspc.&nbsp maybe....
<p><br>

<center><p><input type=button name="but" value="submit" onclick="ch()">
<p>total marks<input type="text" name=t1 size="3">
<p><input type="button" value="finish" onclick="info()"></center>
</form>
</body>
</html>

Attached File(s)


This post has been edited by JackOfAllTrades: 26 June 2010 - 01:03 PM
Reason for edit:: Moved code to post.


Is This A Good Question/Topic? 0
  • +

Replies To: check the error

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3480
  • View blog
  • Posts: 10,027
  • Joined: 08-June 10

Re: check the error

Posted 26 June 2010 - 01:20 PM

are there any error messages in the error console?
Was This Post Helpful? 0
  • +
  • -

#3 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6035
  • View blog
  • Posts: 23,417
  • Joined: 23-August 08

Re: check the error

Posted 26 June 2010 - 01:23 PM

Outside of the atrocious use of txt-speak, there are a lot of errors just to my fairly untrained eye...

else if(fr.t1.vale="22")


vale?
Was This Post Helpful? 0
  • +
  • -

#4 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3710
  • View blog
  • Posts: 5,958
  • Joined: 08-June 10

Re: check the error

Posted 26 June 2010 - 01:54 PM

There are a LOT of problems with that code.

Make sure the parenthesis are correctly positioned. Fore example if((true)||false)&&(true) would give you a syntax error. It should be if((true||false)&&true). (Pay special attention to lines #6, 12 and 18 in your code.)

Also, in your HTML, always enclose attribute values in quote marks. If you don't you can't use spaces.
<input value=Some text>
<!-- The input box only shows: "Some" -->

<input value="Some text">
<!-- The input box shows: "Some text">



View PostJackOfAllTrades, on 26 June 2010 - 07:23 PM, said:

Outside of the atrocious use of txt-speak, there are a lot of errors just to my fairly untrained eye...

else if(fr.t1.vale="22")


vale?

Not to mention that this assigns the value, rather than check it. (== to check, = to assign.)

P.S.
Also, Indentation. Nuff said.

This post has been edited by Atli: 26 June 2010 - 01:58 PM

Was This Post Helpful? 1
  • +
  • -

#5 husseycoding  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 52
  • View blog
  • Posts: 174
  • Joined: 23-June 10

Re: check the error

Posted 26 June 2010 - 02:35 PM

You can also if you wish shorten the length of the if statements by using

if (fr.q1.checked)
{

...

}


and

if (!fr.q1.checked)
{

...

}


instead of

if (fr.q1.checked==true)
{

...

}


and

if (fr.q1.checked==false)
{

...

}


Won't change the way the code works, will just neaten things up and save a few lines.

This post has been edited by husseycoding: 26 June 2010 - 02:39 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1