onsubmit的运用

onsubmit的运用

今天第一次用onsubmit做控制,没想到还不是很容易,查了好多网页终于出来了
我的代码

[复制到剪切板]
CODE:
<?php
if(isset($_POST['name'])){
if((
$_POST['name'] == 'good')){
echo 
"你已经得到值";
}
else{
echo 
"不是good";
}
}
else{
echo 
"是空的";
}
?>
<
html>
<
head>
<
meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<
title>Insert title here</title>
<
script language="javascript">
var 
tes document.getElementByName("name");
var 
dd=tes.value;
function 
check(){
if(
pp.name.value != ""){
alert("已经提交");tes.value=dd;
alert(pp.text.value);
return 
true;
}else{
alert("不对");
return 
false;
}
}
<\/
script>
</
head>
<
body>
<
form action=nn.php method=post name=pp onSubmit="return(check())">
<
input type="text" name="name" onfocus="value='good'" />
<
input type="submit" name="submit" value="提交">
</
form>
</
body>
</
html> ;

-----------------------------------------------------------------------------------------------------------------------------
我用PHP语句来查看是否完成提交
最开始我的<html>前还有一句
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
估计是验证网页正确性的
我在IE中能得到我要的效果,但是在firefox中弹不出对话框,还有就是总是提交的
我吧这一句删掉就正确了,不解



[ 本帖最后由 manx00 于 2008-7-18 15:14 编辑 ]

很多其他情况我也像你这样解决。也是一知半解。
如履薄冰



[复制到剪切板]
CODE:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<
head>
<
meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<
title>无标题文档</title>
</
head>
<
script language="javascript" type="text/javascript">
function 
check(oo){
    if(
oo.name.value=="" || oo.pass.value=="")
    
alert('you null');
    return 
false;
}
<\/
script>
<
body>
<
form id="form1" name="form1" method="post" action="http://www.baidu.com" onsubmit="return check(this);">
  <
input type="text" name="name" />
  <
input type="text" name="pass" />
  <
input type="submit" value="click me" />
</
form>
</
body>
</
html> ;

我的测试没有问题哦。

恩看看 学习