Page 1 of 1

JS - Form action vs. field "action"

Posted: Mon Aug 14, 2006 1:46 pm
by tomprogers
I'm trying to read the value of a form's action attribute. Previously, I was using the following code:

Code: Select all

var sAction = oForm.action;
Unfortunately, one of the forms I'm working with has a field named "action," and the input object was being returned, instead of the string value for the form tag's action attribute. Once I realized what the problem was, I changed it to this:

Code: Select all

var sAction = oForm.getAttribute("action");
While this fixed the problem in Firefox, IE still returns the input object. Any ideas how I can specifically grab the action attribute, or perhaps an array, one element of which is the action attribute, and the other of which is the input field?

I can't change the form itself in any way, just the JS.

Posted: Mon Aug 14, 2006 1:54 pm
by feyd
element.attributes, I believe, is the named node array used by the DOM.

Fixed

Posted: Mon Aug 14, 2006 1:56 pm
by tomprogers
You are correct, sir.

The code that works in IE & FF is:

Code: Select all

var sAction = oForm.attributes.action.value;