cre*_*eam 1 javascript forms return handler onsubmit
我正在努力确保某些字段在我的表单中不会留空.它似乎很简单,但由于某种原因,它不起作用.警报未显示,并且返回false不起作用(它继续将空白条目发布到我的数据库中)请帮助,我做错了什么.谢谢!
剧本:
function check(){
var name = getElementById('name');
var date = getElementById('date');
var pri = getElementById('pri');
var asapc = getElementById('asapc');
var asapn = getElementById('asapn');
var obr = getElementById('obr');
var obc = getElementById('obc');
var obn = getElementById('obn');
if (name.value == "" || date.value == "" || pri.value == "not" || asapc.value == "" || asapn.value == "" || obr.value == "" || obc.value == "" || obn.value == "") {
alert( "One or more fields were not filled out." );
return false ; }
return true;
}
Run Code Online (Sandbox Code Playgroud)
代码:
<FORM ACTION="step2.php" METHOD="POST" onsubmit="check();">
<!-- fields here -->
<INPUT TYPE="submit" VALUE="CONTINUE">
Run Code Online (Sandbox Code Playgroud)
访问每个元素,document.getElementById...并在表单标签中写入,onsubmit="return check();"而不是onsubmit="check();"
| 归档时间: |
|
| 查看次数: |
11067 次 |
| 最近记录: |