<html>
<head>
</head>
<body>
<script>
function isVisible(){
if(document.getElementById("nt").checked==true){
document.getElementById("opt").style.visibility="hidden";
}
else{
document.getElementById("opt").style.visibility="visible";
}
}
</script>
<form align="center" method="post">
<input type="radio" name="teaching" id="t" value="teaching" onchange="isVisible()"> Teaching<br>
<input type="radio" name="teaching" id="nt" value="non-teaching" onchange="isVisible()"> Non-teaching<br>
Post Code <input type="text" name="pcode" id="pcode"><br>
Post Name <input type="text" name="pname" id="pname"><br>
<div id="opt">
Department <input type="text" name="dept" id="dept">
</div>
<input type="button" name="addv" id="addv" value="Add Vacancy" onclick="javascript: form.action='hello.php';">
</form>
</body>
</html>上面是addvacancy.php。单击“添加空缺”按钮时,它不会指向hello.php。它保持在相同的页面上,保留文本框中的值。下面是hello.php的代码。
hello.php
<html>
<head>
</head>
<body>
<?php
echo "Hello!";
?>
</body>
</html>发布于 2016-05-03 18:04:25
您需要向表单中添加一个action,并且应该从您的input中删除onclick事件,如下所示:
<input type="submit" name="addv" id="addv" value="Add Vacancy">并向表单中添加指向表单提交所要指向的URL的操作,如下所示:
<form action="hello.php" align="center" method="post">这应该能起作用。action属性告诉浏览器将表单数据发送到处理表单的PHP页面。
https://stackoverflow.com/questions/37011240
复制相似问题