我有一個表單,下面是代碼 而當點擊提交時,它返回true
而不是顯示 textfiled
爲空,它應該會給出一些錯誤。表單驗證失敗
它是一個簡單的表單驗證
HTML
<form name="rt-form2" method="post" onsubmit="return validateform();">
<input type="text" value="Name" name="name2" id="name1"><br>
<input type="text" value="Email" name="Email" id="Email1"><br>
<input type="text" value="Phone Number" name="phone" id="phone1"><br>
<input type="submit" value="submit" name="submitm" class="submit-btn">
</form>
和JavaScript驗證
<script type="text/javascript">
function validateform(){
alert("Submit button is clicked");
if(document.rt-form2.name2.value.length < 1) {
alert("Enter name");
return false;
}
else {
alert("Submitting");
return true;
}
}
</script>
does document.rt-form2.name2.value.length選擇器甚至工作? – anderssonola 2012-01-11 14:46:33