Firefox中的表单"未定义"错误

tsu*_*man 6 javascript forms

我有这个代码,让我们说吧 a.html

<form name="frmSubmit" id="frmSubmit" method="post">
<input type="hidden" name="hdnName" value="user name" />
</form>

<script>
// 1 : start
document.frmSubmit.action = 'b.html';
document.frmSubmit.submit();
// 1 : end

// 2 : start
document.getElementById("frmSubmit").action = 'b.html';
document.getElementById("frmSubmit").submit();
// 2 : end
</script>
Run Code Online (Sandbox Code Playgroud)

12在IE(IE 8)工作,而不是在FF(3.6.10).Firebug给我以下错误:

document.frmSubmit未定义

我该如何解决?

Jig*_*shi 1

<html>
<head>

<script>
function setup(){
// 1 : start
document.frmSubmit.action = 'b.html';
document.frmSubmit.submit();
// 1 : end

// 2 : start
document.getElementById("frmSubmit").action = 'b.html';
document.getElementById("frmSubmit").submit();
// 2 : end
}
</script>
</head>
<body onload="setup()">
<form name="frmSubmit" id="frmSubmit" method="post">
<input type="hidden" name="hdnName" value="user name" />
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)