<form name="form1" method="post" action="register_step2.php">
<input name=user_id>
<input class=button name=submit type=button value=提交 onclick=formCheck()>
</FORM>
<script>
function formCheck(){
var s=document.form1.user_id.value;
if(s==""||s.indexOf(" ")!=-1) {
alert("不能为空");
document.form1.user_id.select();
return;
}
form1.submit();
}
</script>

解决方案 »

  1.   

    <form name="form1" method="post" action="register_step2.php">
    <input class=button name=submit type=button value=提交 onclick=formCheck()>function formCheck()
    {
    var s=document.form1.user_id.value;

    for(var i=0;i<s.length;i++){
     if(s.substr(i,1)==" ")
     {
    alert("不能为空");
    document.form1.user_id.focus();
    return;
     }
    }
    form1.submit();
     }
      

  2.   

    name=submit改成 name=submit2<form name="form1" method="post" action="register_step2.php" >
    <input name=user_id>
    <input class=button name=submit2 type=button value=提交 onclick=formCheck()>
    </FORM>
    <script>
    function formCheck(){
    var s=document.form1.user_id.value;
    if(s==""||s.indexOf(" ")!=-1) {
    alert("不能为空");
    document.form1.user_id.select();
    return;
    }
    form1.submit();
    }
    </script>
      

  3.   

    name=submit改成 name=submit2<form name="form1" method="post" action="register_step2.php" >
    <input name=user_id>
    <input class=button name=submit2 type=button value=提交 onclick=formCheck()>
    </FORM>
    <script>
    function formCheck(){
    var s=document.form1.user_id.value;
    if(s==""||s.indexOf(" ")!=-1) {
    alert("不能为空");
    document.form1.user_id.select();
    return;
    }
    form1.submit();
    }
    </script>