Page 1 of 1

form กรอกไม่ครบ alert

Posted: 11/01/2011 10:21 pm
by raccoon
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<b><font face="Verdana"><font size=+1>Form Validation Example: Feedback Form</font></font></b>
<br><script LANGUAGE="JavaScript">
<!--

function ValidateForm(form){
ErrorText= "";
if (form.username.value == "") {ErrorText= "\nPlease enter your name"}

if ((form.email.value == "" || form.email.value.indexOf('@', 0) == -1) || form.email.value.indexOf('.') == -1){
ErrorText+= "\nPlease enter a proper value for your email"}
if (form.feedback.value == "") {ErrorText+= "\nPlease enter your feedback"}
if (ErrorText!= "") {
alert("Error :" + ErrorText);
return false;
}
if (ErrorText= "") { form.submit() }
}

-->
</script>

<br><form name="feedback" action="mailto:webgimmicks@email.com" method=post>
<dl>
<dt>
<font face="Verdana">
<pre>
Please enter the following(To test form validation, skip entering one of the fields and click 'Submit' button):
</pre>
</font>
<font face="Verdana">Name: &nbsp;</font><input type="text" value="" name="username" size=30></dt>
<dt> <font face="Verdana">E-mail: &nbsp;</font><input type="text" value="" name="email" size=30></dt>
<dt> <font face="Verdana">Feedback:</font></dt>
<dt><textarea rows=7 cols=60 name="feedback"></textarea></dt>
</dl>
<input type="button" name="SubmitButton" value="Submit" onClick="ValidateForm(this.form)">
<input type="reset" value="Reset">
</form>
<pre><font face="Verdana"><font size=+0>&nbsp; &nbsp;</font></font>
</pre>
</body>
</html>