js 提交页面问题
如下代码 提交表单 点了报错 对话框 就进入下个接收页面了如何让他 保持在原页面?
<form id="form1" name="form1" method="post" action="Untitled-1.html">
<input type = "checkbox" id="checkbox" onclick="on_hide();"/>
<input type = "text" id="name" style="display:none;" />
<input type = "text" id="pass" style="display:none;" />
<input type = "submit" id="up" value = "提交表单" onclick="on_up();"/>
<script>
function on_hide(){
document.getElementById("name").style.display = document.getElementById("pass").style.display = (document.getElementById("checkbox").checked == true) ? "block" : "none";
}
function on_up(){
var chebox = (document.getElementById("checkbox").checked == true) ? "block" : "none";
if(chebox=="block"){
if(document.getElementById("name").value==""){
alert("框1没有输入数据");}else if(document.getElementById("pass").value==""){
alert("框2没有输入数据");}else {alert("框1的内容:"+ document.getElementById ("name").value+"<tr>"+"框2的内容:"+document.getElementById("pass").value);}
}
}
</script>
</form>