[jQuery] Changing form action with hidden field named action in IE causes error
The long subject says it all!
If I have a hidden field named 'action', trying to change the form
action attribute fails in IE7.
If I change the hidden field to something other than action it works.
Can anyone think of a way around this? I would like to keep the hidden
field named 'action' if I can.
Is this a jquery bug, an IE7 bug, a quirk in JS or am I in the wrong
for naming a field 'action'?
Here's some sample code to see the problem:
<script type="text/javascript" src="/shared-scripts/
jquery-1.2.1.min.js"></script>
<form method="post" id="agentForm" action="nowhere.html">
<input type="hidden" name="action" value="No value" />
<input type="text" name="agentName" id="agentName" value="" />
<input type="submit" name="saveAgent" id="saveAgent" value="Save" />
</form>
<button id="debug">Debug this fecking page!</button>
<script type="text/javascript">
$(function() {
$("#saveAgent").click(function() {
// This should alert 'nowhere.html'
alert("action before: " + $("#agentForm").attr("action"));
// Change to 'somewhere.html'
$("#agentForm").attr("action", "somewhere.html"); // No worky in
IE7!
// This should alert 'somewhere.html' but doesn't in IE7
alert("action changed to: " + $("#agentForm").attr("action"));
});
});
</script>