0

I am trying to validate the fields in the form and trying to POST the input after validating form the server however I am able to validate the fields but not able to POST the data form the field, please help if anyone could.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Contact Us</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <SCRIPT LANGUAGE="JavaScript">
function readText (form) {
    varFname=form.fName.value;
	varLname=form.lName.value;
	varEname=form.eMail.value;
	varComment=form.comment.value;
	if(varFname=="")
	{
    alert("Please enter your First Name.");
    form.fName.focus();
    return false;
	}
	else if(varLname=="")
	{
	alert("Please enter your Last Name.");
	form.lName.focus();
	return false;
	}
	
else if ((varEname.indexOf(".", 0) < 0) || (varEname.indexOf("@", 0) < 0) || varEname=="" || varEname.length < 5)
	{
	alert("Please enter valid E-mail address.");
	form.eMail.focus();
	return false;
	}
	else if(varComment=="")
	{
	alert("Please enter questions or comments.");
	form.comment.focus();
	return false;
	}
	else
	{	
	alert ("Form submitted successfully");
	return true;
	}
}
</script>	
</head>
<body>
<FORM NAME="myform" ACTION="http://webdevfoundations.net/scripts/formdemo.asp" METHOD="POST">
	 <fieldset><legend>Questions or Comments:</legend><br />
       <label>First Name: <INPUT TYPE="text" NAME="fName" VALUE=""><br /></label><br />
       <label>Last Name: <INPUT TYPE="text" NAME="lName" VALUE=""><br /></label><br />
       <label>E-Mail:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<INPUT TYPE="text" NAME="eMail" VALUE=""></label> <br /><br />
     </fieldset> <br />
       <label>Questions or Comments:<br /></em>
    <textarea ROWS="4" COLS="60" NAME="comment" VALUE=""></textarea></label><br /><br />
    <INPUT TYPE="Button" NAME="Submit" Value="Submit"onClick=" readText(this.form)"/>  
    <input type="reset" />
</FORM>
</body>
</html>
2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by Luckychap
0

Two issues:-
1. The input type at line 55 should of type "submit"
2. onClick should return true/false to stop/start sending data to server.

Line 55 should be

<INPUT TYPE="submit" NAME="Submit" Value="Submit" onClick="return readText(this.form)"/>

Edited by Luckychap: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.