Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Form "is undefined" error in Firefox

I have this code, let say it's 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>

Both 1 and 2 are working in IE (IE 8), but not in FF (3.6.10). Firebug gives me the following error:

document.frmSubmit is undefined

How can I fix it?

like image 544
tsurahman Avatar asked Sep 29 '10 08:09

tsurahman


1 Answers

<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>
like image 194
jmj Avatar answered Sep 28 '22 14:09

jmj