N
Newbie
Hi everybody,
I made a website which includes some Javascript to check if the "Input
Fields" are empty when clicking on the "Submit" button.
If any of the fields are empty, an error should be displayed and no data
shall be send by email.
But the Javascript is not working and empty fields are still accepted.
What is wrong with the code in the Javascript?
TIA
**************************************
The code in the file (contact.html) looks like this:
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
...........
<script language=JavaScript>
<!--
function checkForm1()
{
if (document.forms.Form1.elements['name'].value.length == 0) {
alert('Please enter a value for the "name" field');
return false;
}
if (document.forms.Form1.elements['email'].value.length == 0) {
alert('Please enter a value for the "Your email address" field');
return false;
}
if (document.forms.Form1.elements['comments'].value.length == 0) {
alert('Please enter a value for the "comments" field');
return false;
}
return true;
}
//-->
</script>
</head>
<body>
<form action="http://www.domain.com/domainmail"
enctype="multipart/form-data" method="POST">
<table border="0" cellspacing="0" cellpadding="0" width="500" height="300">
<td height="30" width="390" valign="top" align="right"><input name="name"
type="text" id="name" size="60"></td>
<td height="30" width="390" valign="top" align="right"><input
name="mailfrom" type="text" id="email" size="60"></td>
<td height="30" width="390" valign="top" align="right"><textarea
style="margin-top:0;margin-bottom:0;width:380px;height:100px;"
name="comment" type="text" id="comment"></textarea></td>
</table>
<div id="but1" style="position:absolute; left:120px; top:350px;"><input
name="Reset" type="reset" id="rst"></div>
<div id="but2" style="position:absolute; left:400px; top:350px;"><input
type="submit" value="Send Email" onClick="chkForm1"><input type="hidden"
name="sendtoemail" value="(e-mail address removed)">
</div>
</form></div>
</body>
</html>
I made a website which includes some Javascript to check if the "Input
Fields" are empty when clicking on the "Submit" button.
If any of the fields are empty, an error should be displayed and no data
shall be send by email.
But the Javascript is not working and empty fields are still accepted.
What is wrong with the code in the Javascript?
TIA
**************************************
The code in the file (contact.html) looks like this:
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
...........
<script language=JavaScript>
<!--
function checkForm1()
{
if (document.forms.Form1.elements['name'].value.length == 0) {
alert('Please enter a value for the "name" field');
return false;
}
if (document.forms.Form1.elements['email'].value.length == 0) {
alert('Please enter a value for the "Your email address" field');
return false;
}
if (document.forms.Form1.elements['comments'].value.length == 0) {
alert('Please enter a value for the "comments" field');
return false;
}
return true;
}
//-->
</script>
</head>
<body>
<form action="http://www.domain.com/domainmail"
enctype="multipart/form-data" method="POST">
<table border="0" cellspacing="0" cellpadding="0" width="500" height="300">
<td height="30" width="390" valign="top" align="right"><input name="name"
type="text" id="name" size="60"></td>
<td height="30" width="390" valign="top" align="right"><input
name="mailfrom" type="text" id="email" size="60"></td>
<td height="30" width="390" valign="top" align="right"><textarea
style="margin-top:0;margin-bottom:0;width:380px;height:100px;"
name="comment" type="text" id="comment"></textarea></td>
</table>
<div id="but1" style="position:absolute; left:120px; top:350px;"><input
name="Reset" type="reset" id="rst"></div>
<div id="but2" style="position:absolute; left:400px; top:350px;"><input
type="submit" value="Send Email" onClick="chkForm1"><input type="hidden"
name="sendtoemail" value="(e-mail address removed)">
</div>
</form></div>
</body>
</html>