我想当用户没有输入id时 不执行 form2.action=form2.action + "?kk=" + iRows;但我写的有错
始终都要执行function form2_check(){ if (document.all("id").value==""){
alert("必须输入id");
document.all("id").focus();
return false;
}
form2.action=form2.action + "?kk=" + iRows;
return true;
}
始终都要执行function form2_check(){ if (document.all("id").value==""){
alert("必须输入id");
document.all("id").focus();
return false;
}
form2.action=form2.action + "?kk=" + iRows;
return true;
}
<table border="0"align="center">
<tr>
<td class="class1">id:</td><td class="class2"><input class="class2" name="id" size="10"><td>
</tr>
<tr>
<td><input type="submit" value="保存" id=submit1 onclick="form2_check()">
<input type="reset" value="清 除" id=reset1></td>
</tr>
</table>
</form>
function form2_check(){
alert(document.all("id").value); //建议先看看自己判断条件对了不
if (document.all("id").value==""){
alert("必须输入id");
document.all("id").focus();
return false;
}
form2.action=form2.action + "?kk=" + iRows;
return true;
}
<table border="0"align="center">
<tr>
<td class="class1">id:</td><td class="class2"><input class="class2" name="id" size="10"><td>
</tr>
<tr>
<td><input type="submit" value="保存" id=submit1>
<input type="reset" value="清 除" id=reset1></td>
</tr>
</table>
</form>
然后在form2.action=form2.action + "?kk=" + iRows;后面加上form2.submit();
具体如下:<script>
function form2_check(){
if (document.all("id").value==""){
alert("必须输入id");
document.all("id").focus();
return false;
} form2.action=form2.action + "?kk=" + iRows;
form2.submit();
return true;
}
</script><form action="submit.asp" method= "post" id="form2" name="form2" target="refresh">
<table border="0"align="center">
<tr>
<td class="class1">id:</td><td class="class2"><input class="class2" name="id" size="10"><td>
</tr>
<tr>
<td><input type="button" value="保存" id=submit1 onclick="form2_check()">
<input type="reset" value="清 除" id=reset1></td>
</tr>
</table>
</form>