dummyagain
September 25th, 2006, 03:18 AM
I don't know why the script will not able to call the checkform function
<head>
<meta http-equiv="Content-Type" content="text/html; charset=big5">
<title>Contact Us</title>
<script language="JavaScript">
function checkForm()
{
alert("Test");
var name, email,tel,subject, comment;
with(window.document.contactus)
{
name = name;
email = email;
tel = tel;
subject = subject;
comment = comment;
}
if(trim(name.value) == '')
{
alert('Please enter your name');
name.focus();
return false;
}
else if(trim(email.value) == '')
{
alert('Please enter your email');
email.focus();
return false;
}
else if(!isEmail(trim(email.value)))
{
alert('Email address is not valid');
email.focus();
return false;
}
else if(trim(tel.value) == '')
{
alert('Please enter contact number');
tel.focus();
return false;
}
else if(trim(subject.value) == '')
{
alert('Please enter message subject');
subject.focus();
return false;
}
else if(trim(comment.value) == '')
{
alert('Please enter your message');
comment.focus();
return false;
}
else
{
name.value = trim(name.value);
email.value = trim(email.value);
subject.value = trim(subject.value);
tel.value = trim(tel.value);
comment.value = trim(comment.value);
return true;
}
}
function trim(str)
{
return str.replace(/^\s+|\s+$/g,'');
}
function isEmail(str)
{
var regex = /^[-_.a-z0-9]+@(([-_a-z0-9]+\.)+(ad|ae|aero|af|ag|
ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|
bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|
ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|
zm|zw)|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i;
return regex.test(str);
}
</script>
</head>
<body>
<form name="contactus" method="post" action="insertc.php">
<p><B><FONT face=Arial size=2>Customer satisfaction has always been our prime objective. Your comments are most valuable to us. <br>
To help us upgrading the quality and standard of our service, please let us have your comments.</FONT></B> </p>
<table width="500" border="1">
<tr>
<td>Name</td>
<td><input type="text" name="name"></td>
</tr>
<tr>
<td>Email</td>
<td><input type="text" name="email"></td>
</tr>
<tr>
<td>Tel No. </td>
<td><input type="text" name="tel"></td>
</tr>
<tr>
<td colspan="2"><FONT face=Arial size=2>Please feel free to write down your comment:</FONT></td>
</tr>
<tr>
<td>Subject</td>
<td><select name="subject">
<option value="suggestion">Suggestion</option>
<option value="others">Others</option>
</select></td>
</tr>
<tr>
<td height="86" colspan="2"><textarea name="comment" cols="80" rows="15"></textarea></td>
</tr>
</table>
<p>
<input type="submit" name="Submit" value="Submit" onClick="return checkForm();">
<input type="reset" name="Reset" value="Reset">
Thank you for your advice
<head>
<meta http-equiv="Content-Type" content="text/html; charset=big5">
<title>Contact Us</title>
<script language="JavaScript">
function checkForm()
{
alert("Test");
var name, email,tel,subject, comment;
with(window.document.contactus)
{
name = name;
email = email;
tel = tel;
subject = subject;
comment = comment;
}
if(trim(name.value) == '')
{
alert('Please enter your name');
name.focus();
return false;
}
else if(trim(email.value) == '')
{
alert('Please enter your email');
email.focus();
return false;
}
else if(!isEmail(trim(email.value)))
{
alert('Email address is not valid');
email.focus();
return false;
}
else if(trim(tel.value) == '')
{
alert('Please enter contact number');
tel.focus();
return false;
}
else if(trim(subject.value) == '')
{
alert('Please enter message subject');
subject.focus();
return false;
}
else if(trim(comment.value) == '')
{
alert('Please enter your message');
comment.focus();
return false;
}
else
{
name.value = trim(name.value);
email.value = trim(email.value);
subject.value = trim(subject.value);
tel.value = trim(tel.value);
comment.value = trim(comment.value);
return true;
}
}
function trim(str)
{
return str.replace(/^\s+|\s+$/g,'');
}
function isEmail(str)
{
var regex = /^[-_.a-z0-9]+@(([-_a-z0-9]+\.)+(ad|ae|aero|af|ag|
ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|
bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|
ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|
zm|zw)|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i;
return regex.test(str);
}
</script>
</head>
<body>
<form name="contactus" method="post" action="insertc.php">
<p><B><FONT face=Arial size=2>Customer satisfaction has always been our prime objective. Your comments are most valuable to us. <br>
To help us upgrading the quality and standard of our service, please let us have your comments.</FONT></B> </p>
<table width="500" border="1">
<tr>
<td>Name</td>
<td><input type="text" name="name"></td>
</tr>
<tr>
<td>Email</td>
<td><input type="text" name="email"></td>
</tr>
<tr>
<td>Tel No. </td>
<td><input type="text" name="tel"></td>
</tr>
<tr>
<td colspan="2"><FONT face=Arial size=2>Please feel free to write down your comment:</FONT></td>
</tr>
<tr>
<td>Subject</td>
<td><select name="subject">
<option value="suggestion">Suggestion</option>
<option value="others">Others</option>
</select></td>
</tr>
<tr>
<td height="86" colspan="2"><textarea name="comment" cols="80" rows="15"></textarea></td>
</tr>
</table>
<p>
<input type="submit" name="Submit" value="Submit" onClick="return checkForm();">
<input type="reset" name="Reset" value="Reset">
Thank you for your advice