HTML
<form name="f1" action="feedback1.php" method="Post" onSubmit="return isDataFilled();" >
<table border="0" align="center" width="500px" style="max-width: 500px;" cellspacing="3" cellpadding="5" align="center">
<tr align="left">
<td width="25%">
Enter your subject </td>
<td width="75%"><input type="text" name="subject" size="30" value="Your subject" onClick="if(this.value=='Your subject'){this.value=''}; this.style.backgroundColor='#CCFF99'" onBlur="if(this.value==''){this.value='Your subject'}; this.style.backgroundColor='white'"/></td>
</tr>
<tr align="left">
<td>
Enter your email<span style="color:#FF0000">*</span> </td>
<td>
<input type="text" name="email" size="30" value="example@mail.com" onClick="if(this.value=='example@mail.com'){this.value=''}; this.style.backgroundColor='#CCFF99'" onBlur="if(this.value==''){this.value='example@mail.com'}; this.style.backgroundColor='white'"/> </td>
</tr>
<tr align="left">
<td colspan="2">
Enter your message here<span style="color:#FF0000">*</span>: </td>
</tr>
<tr align="left">
<td colspan="2">
<textarea rows="10" cols="50" name="message" title="Your message goes here" onClick= "if(this.value=='Your message goes here'){this.value=''}; this.style.backgroundColor='#CCFF99'" onBlur="if(this.value==''){this.value='Your message goes here'}; this.style.backgroundColor='white'" >Your message goes here</textarea> </td>
</tr>
<tr>
<td colspan="" align="right">
<input type="submit" value="Send" name="b1" title="Send your message"/>
</td>
<td align="center">
<input type="reset" value="Reset" name="reset" title="Removes your form data and fill it again"/> </td>
</tr>
</table>
</form
JavaScript
function isDataFilled()
{
if(document.forms['f1']['email'].value=='example@mail.com')
{
alert("No email address in email field!");
return false;
}
if(document.forms['f1']['message'].value=='Your message goes here')
{
alert("No message in message field!");
return false;
}
return isEmailCorrect(document.forms["f1"]["email"].value);
return check_word_length(document.forms['f1']['message'].value, 20);
}
function isEmailCorrect(f_email)
{
var x=f_email;
var atpos=x.indexOf("@");
var dotpos=x.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
{
alert("Not a valid e-mail address");
return false;
}
}
function check_word_length(text, over_size)
{
var word=0;
var message=text;
for(i=0;i<message.length;i++)
{
if(message.charAt(i)==" ")
{
word=0;
}
else
{
word++;
if(word>=over_size)
{
alert("Too long text entered");
return false;
}
}
}
}
该功能check_word_length(text, over_size)
不工作。我很困惑,因为我认为我的代码没问题。