1. You should define a function check() to check the query input.
2. You can call the function check as follows:form action="http://maps.google.com/maps" method="get" name="f" onsubmit="return check()"
==============================
Lab 20
<html>
<title>Lab 20</title>
<body>
<form action="http://maps.google.com/maps" method="get" name="f" onsubmit="return check()">
<input name="q" type="text" />
<input name="send" type="submit" value="search" />
</form>
</body>
<script>
function check()
{ var floatReg =/^([+-]?)[1-9]\d*(\.\d*)?,([+-]?)[1-9]\d*(\.\d*)?$/;
if(!floatReg.test(f.q.value)){
alert("Incorrect format!!!");
f.q.value="";
document.f.q.focus();
return false;
}
}
</script>
</html>
<html>
<title>Lab 20</title>
<body>
<form action="http://maps.google.com/maps" method="get" name="f" onsubmit="return check()">
<input name="q" type="text" />
<input name="send" type="submit" value="search" />
</form>
</body>
<script>
function check()
{ var floatReg =/^([+-]?)[1-9]\d*(\.\d*)?,([+-]?)[1-9]\d*(\.\d*)?$/;
if(!floatReg.test(f.q.value)){
alert("Incorrect format!!!");
f.q.value="";
document.f.q.focus();
return false;
}
}
</script>
</html>
沒有留言:
張貼留言