驗證表單字段的Javascript函數FormQuote_Validator
應返回「TRUE」,並在所有三個輸入字段均未提交任何數字時提醒消息,否則應返回「FALSE」。如何使用「OR」運算符進行表單字段驗證?
下面是HTML代碼:
<form id="gform_1" enctype="multipart/form-data" method="post" action="">
<div>
<li id="field_1_25">
<label for="input_1_25">20 Amps</label>
<input type="number" tabindex="22" class="small" value="" step="any" id="input_1_25" name="input_25">
</li>
<li id="field_1_26">
<label for="input_1_26" class="gfield_label">30 Amps</label>
<input type="number" tabindex="23" class="small" value="" step="any" id="input_1_26" name="input_26">
</li>
<li id="field_1_27">
<label for="input_1_27">40 Amps</label>
<input type="number" tabindex="24" class="small" value="" step="any" id="input_1_27" name="input_27">
</li>
</div>
<button onclick="FormQuote_Validator(gform_1)" type="button">Submit</button>
</form>
這是使用Javascript:
function FormQuote_Validator(Form){
if ((Form.input_25.value == "") || (Form.input_26.value == "") || (Form.input_27.value == "")){
alert("Please input the size in Amps.");
Form.input_1_25.focus();
return (false);
}
}
由於種種原因FormQuote_Validator
函數返回「TRUE」,即使一個或兩個輸入字段以數值提交。腳本代碼有問題嗎?任何幫助,將不勝感激!
什麼不起作用?控制檯中有任何錯誤?請詳細說明_「不工作!」_ – Rayon
似乎爲我工作,請參閱:https://jsfiddle.net/cdLyczr7/ –