Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-10-2013, 12:38 PM   PM User | #1
Coding123
New to the CF scene

 
Join Date: Dec 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Coding123 is an unknown quantity at this point
Javascript Validation Error.

My validation doesn't work. Please help. Here's the code:

Code:
<html>
<body>
<head>
<font face="Candara">

<title>Selection Validator</title>

<script type>="text/javascript" language="Javascript">
function validateChoice(genderForm)  {
genderOption = -1
for (i=0;   i<genderForm.genderChoice.length; i++)  {
if (genderForm.genderChoice[i].checked)  {
genderOption = i
alert ("You are a " + genderForm.genderChoice[i].value)
}
}
if (genderOption ==-1  {
alert ("You must choose either Male or Female.")
return false
}
return true
}
</script>
</head>
</font>
</body>

<nonscript>
Javascript not detected! This page will not work properly.
</nonscript>

<form name ="myForm" onSubmit="return validateChoice(this)">

<p>Select your gender: &nbsp;

<input type="radio" name="genderChoice" value="Male" /> Male
<input type="radio" name="genderChoice" value="Male" /> Female
<input type="submit" value="Validate" />
</p>

</form>
</html>
Coding123 is offline   Reply With Quote
Old 01-10-2013, 01:12 PM   PM User | #2
007julien
Regular Coder

 
Join Date: May 2012
Location: France
Posts: 115
Thanks: 0
Thanked 17 Times in 15 Posts
007julien is an unknown quantity at this point
What is the method of your form GET or POST ? Which file is going to treat the datas ?
007julien is offline   Reply With Quote
Old 01-10-2013, 04:39 PM   PM User | #3
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,395
Thanks: 18
Thanked 351 Times in 350 Posts
sunfighter is on a distinguished road
Code:
<html>
<body>  DOES NOT BELONG HERE
<head>
<font face="Candara"> DOES NOT BELONG HERE AND IS DEPRECIATED

<title>Selection Validator</title>

<script type>="text/javascript" language="Javascript"> PLEASE CORRECT THIS IT IS TOTALLY WRONG
function validateChoice(genderForm)  {
genderOption = -1
for (i=0;   i<genderForm.genderChoice.length; i++)  {
if (genderForm.genderChoice[i].checked)  {
genderOption = i
alert ("You are a " + genderForm.genderChoice[i].value)
}
}
if (genderOption ==-1  { MISSING A CLOSING )
alert ("You must choose either Male or Female.")
return false
}
return true
}
</script>
</head>
</font> DOES NOT BELONG
</body>

<nonscript>
Javascript not detected! This page will not work properly.
</nonscript> REMOVE THIS IT DOES NOT WORK CORRECTLY

<form name ="myForm" onSubmit="return validateChoice(this)"> AS julien SAID, NEEDS AN METHOD  ALSO name ="myForm" S/B ID ="myForm" ALSO NEEDS AN ACTION

<p>Select your gender: &nbsp;

<input type="radio" name="genderChoice" value="Male" /> Male
<input type="radio" name="genderChoice" value="Male" /> Female value="Male" S/B value="female"
<input type="submit" value="Validate" />
</p>

</form>
</html>
Fix code and check again.

Last edited by sunfighter; 01-10-2013 at 04:47 PM..
sunfighter is offline   Reply With Quote
Old 01-10-2013, 10:05 PM   PM User | #4
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,465
Thanks: 0
Thanked 499 Times in 491 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
Quote:
Originally Posted by sunfighter View Post
Fix code and check again.
You missed that the form is after the </body> tag instead of before it where it belongs.

Also the page is missing a DOCTYPE and so will render differently in different browsers
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:58 AM.


Advertisement
Log in to turn off these ads.