2013年10月24日 星期四

102-1_Lab15 Hand code a form

助教悲劇補充:現在依然無法判斷大小

<html>
<title>lab14</title>
<body>
<form action="http://maps.google.com/maps" method="get" name="f" onsubmit="return check()">
<input name="q" type="text"  /><br />
<input name="send" type="submit" value="search" />
</form>
</body>
<script>

  var floatReg =/^([+-]?)[1-9]\d*(\.\d*)?,([+-]?)[1-9]\d*(\.\d*)?$/;
//funtion外宣告可以全域使用
var str=",";
f1=f.q.value.indexOf(str);
f2=f.q.value.length;
latitude=f.q.value.substring(0,f1);
longitude=f.q.value.substring(f1+1,f2);
y=parseInt(latitude);
x=parseInt(longitude);
//alert(y);
//alert(x);
//alert(y>90);
//alert(x<180);
//alert(y>90||x>180);
function check(){
if(!floatReg.test(f.q.value)){
alert("It's not correct format");
   f.q.value="";
   document.f.q.focus();
   return false;
}
}
 document.write(Date());
</script>
</html>

沒有留言:

張貼留言