JSが正しく動作していません。どうしてか分かりません。誰でも助けてくれますか?ここに私のコードがある...ここでJavascriptフォームの検証が正しく機能していません
function validate() {
if(document.contactform.name.value==''){
alert('Fill the Input name');
name.focus();
return false;
}
if(document.contactform.email.value==''){
alert('Fill the Input email');
email.focus();
return false;
}
if(document.contactform.email.value!=''){
if(!checkEmail(email.value)){
alert('Please specify your correct Email!');
email.focus();
return false;
}
}
if(document.contactform.mobile.value==''){
alert('Fill the Input mobile');
mobile.focus();
return false;
}
if(document.contactform.mobile.value!=''){
if(!IsNumeric(mobile.value)){
alert('Please specify your correct Mobile Number!');
mobile.focus();
return false;
}
}
if(document.contactform.subject.value==''){
alert('Fill the Input Subject');
subject.focus();
return false;
}
if(document.contactform.message.value==''){
alert('Fill the Input description');
message.focus();
return false;
}
if(!document.contactform.agree.checked){
alert('Please check the terms and conditions');
return false;
}
else{
return true;
}
}
はコードだけでは名前フィールドのために働いていない
<form name="contactform" id="form" class="form" action="newmail.php" onsubmit="return validate();" method="post">
<TABLE align="center" border="0">
<TR><TD align="right"> <b>Name :</b></TD><TD align="left"><input type="text" name="name" id="name" /></TD></TR>
<TR><TD align="right"> <b>Email :</b></TD><TD align="left"><input type="text" name="email" id="email" /></TD></TR>
<TR><TD align="right"> <b>Mobile :</b></TD><TD align="left"><input type="text" name="mobile" id="mobile" /></TD></TR>
<TR><TD align="right"> <b>subject :</b></TD><TD align="left"><input type="text" name="subject" id="subject" /></TD></TR>
<TR><TD align="right"> <b>Message :</b></TD><TD align="left"><textarea name='message' id='message'></textarea></TD></TR>
<TR><TD colspan="2" align="center"><label for="agree"><input type="checkbox" name="agree" id="agree" checked="checked"> I agree to terms and Conditions</label> </TD></TR>
<TR><TD colspan="2" align="center"><input type="submit" value="Submit" class="submit" /> </TD></TR>
</TABLE>
</form>
...私のhtmlです。私が提出した名前のコードをコメントすれば正常に動作します。何が問題なの?私の他のフォームでは、textareaフィールドだけでは機能しません。このフォームのメッセージフィールドでは、テキストエリアの検証が機能しています。
これは何が起こるかです。私がフォームを提出するとき、名前が空であれば、それは警告を表示し、直接目標ページに行く。名前の検証のためにコードにコメントすると、コードの残りの部分は関連エラーを警告することで正常に動作します。
「$ DEITY」の愛については、http://stackoverflow.com/editing-helpを参照してください。 –
どうしますか、しませんか?それは何を期待していますか? – Cfreak
投稿が偽を返さず、送信をブロックしないようにエラーが発生しました –