Forum Moderators: open
1 - Need help on only character (a to z) and space are allowed, no number.
2 - The email how to made it check to be a vaild email, just hav @ & . in it will do. even if the user enter 1@1.1 is ok too.
3 - My radio button i cant seem to get it working, have to select either one to continue.
<html>
<title> Kelvin's Guestbook </title>
<HEAD>
<style>
H1, H2, H3, H4, H5, H6 {color:#D4A017; text-align:center}
blockquote {background-color:#ff0000}
</style>
<SCRIPT LANGUAGE="JavaScript"><!--
function validate_form ()
{
valid = true;
if ( document.Assignment_2.Fname.value == "" )
{
alert ( "Please fill in the 'First Name' box." );
valid = false;
}
if ( document.Assignment_2.Lname.value == "" )
{
alert ( "Please fill in the 'Last Name' box." );
valid = false;
}
if ( document.Assignment_2.email.value == "" )
{
alert ( "Please fill in the 'E-mail' box." );
valid = false;
}
if ( document.Assignment_2.country.value == "" )
{
alert ( "Please fill in the 'Country' box." );
valid = false;
}
if (document.Assignment_2.sex.checked == false)
{
alert("Pls Select Your Gender");
valid = false;
}
if ( document.Assignment_2.age.selectedIndex == 0 )
{
alert ( "Please select your Age." );
valid = false;
}
if ( document.Assignment_2.rating.selectedIndex == 0 )
{
alert ( "Please chose a Rating." );
valid = false;
}
return valid;
}
//-->
</SCRIPT>
</head>
<body>
<form name="Assignment_2" method="post" onSubmit="return validate_form()">
<h1>Welcome to my Guestbook
</h1>
<center>
<table border="0">
<br>First Name : <input type="text" name="Fname" size="30">
<br>Last Name : <input type="text" name="Lname" size="30">
<br>E-Mail : <input type="text" name="email" size="30">
<br>Country : <INPUT TYPE="text" name="country" SIZE=30 MAXLENGTH=74>
<br>Gender : <input type="radio" name="sex" value="Male"> Male
<input type="radio" name="sex" value="Female"> Female
<br>Age:
<select name="age">
<option value="">Please Select an Option:</option>
<option value="0-18 years">0-18 years</option>
<option value="18-30 years">18-30 years</option>
<option value="30-45 years">30-45 years</option>
<option value="45-60 years">45-60 years</option>
<option value="60+ years">60+ years</option>
</select>
<br>My Website Rating:
<select name="rating">
<option value="">-- SELECT --</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
<br>Comments: *Optional
<br><textarea cols="50" rows="8" name="Coments"></textarea>
</table>
<input type="submit" name="send" value="Sign My Guestbook">
<INPUT TYPE="reset" name="reset" value="Clear">
</center>
</FORM>
<hr>
<BLOCKQUOTE>
<MARQUEE scrollamount="5">
<P STYLE="COLOR:#000000; FONT-SIZE: 100%; FONT-WEIGHT:BOLDER">
Best View On 1280 * 1024 Resolution
</P>
</MARQUEE>
</BLOCKQUOTE>
<hr>
</body>
</html>
To be honest, with the javascript I would just check to see if the user entered data, instead of checking the formatting here. The guestbook that you are writing has to have some form of server-side scripting going on and this is where you want to completely validate the data that you are getting. This is because javascript can be disabled, worked around, etc and isn't very reliable. The only thing javascript does in a case like this is tells a legitimate user that his input is malformed before the form is submitted, which, is a good thing and increases smoothness of the UI, however it's not essential.
Anyway, to get what you want you are going to have to take a look at regular expressions [developer.mozilla.org] with javascript. Get familiar writing the patterns because you'll probably be using them server-side, too, for validation ;)
var Fname=document.getElementById('Fname').value;
if(!/^[A-z]*$/+$/.test(Fname)){
msg+='- Only Letter & Space '+email+'\n\n';}
Im creating this for a sch assignment dont need send data to server just hav to validate some of the field & when all the required field r fill in, it will open up the outlook express.