<html>
<head>
<script type="text/javascript" src="update.js"></script>
<form action = "update.php" method = "POST">
</form>
</head>
<body>
<form action = "test.php" onsubmit="return my_check()" method = "POST">
<table>
<tr><td><label for = "id">文件号:</label></td><td><input type = "text" size="8" name = "id" id='my_id' /></td></tr>
<tr><td><label for = "user">姓名:</label></td><td><input type = "text" size = "8" name = "user" /></td></tr>
<tr><td><input type = "submit" name = "submit" value = "提交更新"/>
<input type = "hidden" name = "action" value = "add" />
<input type = "reset" name = "reset" value = "重新填写" /></td></tr>
</table>
</form>
</body>
</html>
<script language=javascript>
function my_check(){
var a = document.getElementById("my_id")
if(a.value==""){
alert ("文件号不能为空"+"\n"+"请加上")
a.focus()
return(false)
}
else{
return(true)
}
}
</script>
<?
$act = $_POST['action']
if($act == 'add'){
$id = $_POST['id']
echo "您输入了".$id
}
?>
呵呵,明白你的意思了。你可以这样做。第一种方法,就是直接在js脚本里嵌入php代码:
if(document.myform.check.value!="<?=$_session['check']?>"){
..........
}
方法二:就是设置一个隐藏域,用来装session的值。这样就和验证用户名一样了。