當'roll'輸入字段未提供任何值時,'empty()'函數產生警報,但該空值仍然傳遞給'retrive.php'如何阻止這種情況的發生,並且只在提供一些輸入值時將值傳遞給'retrive'.php。當輸入字段爲空時阻止表單提交
<html>
<head>
<title>STUDENT FORM</title>
<script type="text/javascript">
function empty()
{
var x;
x = document.getElementById("roll-input").value;
if (x == "")
{
alert("Enter a Valid Roll Number");
};
}
</script>
</head>
<body >
<h1 align="center">student details</h1>
<div id="input">
<form action='retrive.php' method='get'>
<fieldset>
<legend>Get Details</legend>
<dl>
<dt><label for="roll-input">Enter Roll Number</label></dt>
<dd><input type="text" name="roll" id="roll-input"><dd>
<input type="submit" value="submit" onClick="empty()" />
</dl>
</fieldset>
</form>
</div>
</body>
</html>
快14秒,並與jsfiddle! +1你好 – 2013-04-11 16:27:47
@ j08691非常感謝。 – Pawan 2013-04-11 16:36:48
偉大的幫助。謝謝 :-) – 2017-03-22 07:51:42