I don't know xhtml
<form name="validation_form" method="post" onsubmit="return validate()" action="demo_form.asp">
onsubmit="return validate()"
function validation()
function validation()
must be
function validate()
Don't write <SCRIPT LANGUAGE="JavaScript"> in the javascript file
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
instead of
<!DOCTYPE html PUBLIC ″-//W3C//DTD XHTML 1.0 Strict//EN″
http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd>
The code I tried:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<title> Javascript Form Validation Homework </title>
<script type="text/javascript">
// http://www.mustafaaydemir.org/xhtml-formlar.html
// http://learnwebsitedesign.com/xhtml_tutorials/xhtml_tutorial.php
// http://csshtmltutorial.com/csshtmltutorial-htmlformcodetutorial.php
// http://www.elated.com/articles/form-validation-with-javascript/
// http://www.w3schools.com/html/html_forms.asp
// http://www.w3schools.com/html/tryit.asp?filename=tryhtml_radio
// http://www.w3schools.com/html/tryit.asp?filename=tryhtml_form_radio
// http://www.w3schools.com/js/js_form_validation.asp
// http://www.w3schools.com/js/tryit.asp?filename=tryjs_form_validation
// http://www.w3resource.com/javascript/form/example-javascript-form-validation.html
// http://www.w3resource.com/javascript/form/javascript-sample-registration-form-validation.php
// http://www.webdeveloper.com/forum/showthread.php?t=258487
function validation() {
var x=document.forms["validation_form"]["YourName"].value;
if (x==null || x=="")
{
alert("Name must be filled out");
return false;
}
var m=document.forms["validation_form"]["YourEmail"].value;
if (m==null || m=="")
{
alert("E-mail Address must be filled out");
return false;
}
var p=document.forms["validation_form"]["YourPassword"].value;
if (p==null || p=="")
{
alert("Password must be filled out");
return false;
}
var pc=document.forms["validation_form"]["passwordConfirmed"].value;
if (pc==null || pc=="")
{
alert("Re-Type Password must be filled out");
return false;
}
var r0=document.forms["validation_form"]["Gender"][0].checked;
var r1=document.forms["validation_form"]["Gender"][1].checked;
if (r0==false && r1 == false )
{
alert("Please choose your Gender: Male or Female");
return false;
}
var c=document.forms["validation_form"]["Comments"].value;
if (c==null || c=="")
{
alert("Comments must be filled out");
return false;
}
return true;
}
</script>
</head>
<body>
<form name="validation_form" onsubmit="return validation()" action="demo_form.asp" method="post" >
<fieldset>
<legend>Registration Form </legend>
<p>Name: <input type="text" name="YourName" size="10" maxlength="10"/></p>
<p>E-mail Address: <input type="text" name="YourEmail" size="10" maxlength="24"/></p>
<p>Password: <input type="password" name="YourPassword" size="10" maxlength="10"/></p>
<p>Re-Type Password:<input type="password" name="passwordConfirmed" size="10" maxlength="10"/></p>
<p>Your Gender:
<input type="radio" name="Gender" Value="Male"> Male
<input type="radio" name="Gender" Value="Female"> Female
</p>
<p>Comments:<input type="text" name="Comments" size="100" maxlength="500" value=""/></p>
<p><input type="submit" value="Submit"/></p>
</fieldset>
</form>
</body>
</html>
other javascript forum:
http://www.sitepoint.com/forums/foru...pt-amp-jQuery&
Last edited by Ayşe; 03-23-2012 at 05:26 PM.
The Time Through Ages
In the Name of Allah, Most Gracious, Most Merciful
1. By the Time,
2. Verily Man is in loss,
3. Except such as have Faith, and do righteous deeds, and (join together) in the mutual enjoining of Truth, and of Patience and Constancy.
Bookmarks