views:

33

answers:

2

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?

A: 
<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>
org.life.java
@tsurahman your comment is not clear.
org.life.java
<p>abcd</p><form> .... it's works, or <br><form> ... it's works to, it's seem I have to add another tag before <form> to make it works
tsurahman
A: 

Usually, when I'm going to code those workarrounds, to avoid an error to halt the execution, I surround conflicting blocks with try&cathc. I would recommend surrounding 1 and 2 with try/catch bloks, so it there is an error there, it does not halt script execution.

SoulWanderer