我有以下代碼來檢查表單數據,我無法弄清楚爲什麼它不工作。Javascript檢查表單數據不起作用
<script type="text/javascript">
function checkStuff() {
// By default, we plan to submit the form.
var formOkay = 1;
// Check to see if field_1 has a value. If not, we note that by changing our variable.
if(document.getElementById('requestorfirstname').value == '')
formOkay = 0;
// Let the user know something is wrong somehow. An alert is easiest.
alert('Requestor Name Required!');
// If you return true the form will submit. If you return false it will not.
if(formOkay == 1) {
return true;
} else {
return false;
}
}
</script>
現在這裏是html表單的一部分它的檢查onsubmit。
<input type="text" name="requestorfirstname" />
感謝您的幫助!
就是這樣!在我修好之後,表格仍然完成,我需要更改哪些內容才能返回表單而不是繼續?謝謝 – Intelwalk 2012-02-21 15:37:11
這一切都取決於你如何調用這個功能。 – 2012-02-21 15:46:56
當按下按鈕時,我打電話給它。 – Intelwalk 2012-02-21 16:00:40