Archive for September, 2008

Forms With Elements With Form Attribute Names

Tuesday, September 23rd, 2008

I commonly create a form element that dictates the action I want the server to perform, like <input type="hidden" name="action" value="save">. This allows me to have a switch to determine what to do with the data in any situation instead of posting and getting to multiple places. I found a bug in Internet Explorer 7’s JavaScript today that introduces a problem with my naming scheme.

When doing Ajax, I often use form.getAttribute('action') to get the location to send the request to. This allows me to keep my code more portable. However, in Internet Explorer 7 (or IE7 for short), if there is also a form element with name="action", IE7 returns the input object instead of the value of the attribute as though I typed formname.action or, in long hand, document.forms['formname'].elements['action'].

To my knowledge, there is no work around other than changing the name of the element. So, I’ll be using name="faction" from now on. That’s short for “form action” but “faction” itself is fairly apt given IE’s behavior is different from all other browsers, making it a faction.