2013年12月10日 星期二

[javascript] 使用者輸入防呆



按下確定按鈕後,先透過js檢查使用者有無填入資料,再做撈資料庫的動作。

基本上就是注意紅色字就可以了。

<form name="form" method="post"  onsubmit="return chkData();" action="f001.asp">
<input type="submit" name="Search" value="確定"  title="確定"  >
<input type="button"  name="clear" value="重置"  title="重置" onclick="set()">

<%
if request("Search") <> "" then   '按下確定鈕,做查詢

set rs=ExecRecord(sql)
if  rs.eof then
Response.Write "<tr width='100%'><td colspan='6' class='manifesto'>"
Response.Write "目前沒有任何資料 !!"
Response.Write "</td></tr>" 
else 
while not rs.eof
tobeaway_no=trim(rs("tobeaway_no"))
rs.movenext
wend

rs.close
set rs=nothing    
end if
%>
</form>



<script language=javascript>
function set()
document.form.orgid.selectedIndex=0; 
}


function chkData()
{
if ((document.all('orgid').value == "") && (document.all('user').value ==""))
       {
alert("請輸入條件");
return false;    //return false;程式就不會往下執行,防呆用
}
}

<%if mesg<>"" then %>
alert('<%=mesg%>');
<%end if%>

</script>



以上就可以做到javascript防呆了
完畢。




沒有留言:

張貼留言