Bug Tracker

Opened 13 years ago

Closed 13 years ago

Last modified 11 years ago

#160 closed bug (fixed)

a fix for getAttribute('action') in forms

Reported by: Fil Owned by:
Priority: minor Milestone:
Component: core Version:
Keywords: Cc: fil@…
Blocked by: Blocking:

Description

Hello,

there is (apparently) a bug in MSIE if we use getAttribute('action') on a form, because it will give us the action property of the form, instead of the value of its "action" input.

Example :

<form action="url"> <input type="text" name="action" value="ok" /> </form>

this.getAttribute('action') should be "ok", not "url".

A fix for this is to use: this.getAttributeNode('action').nodeValue

(that's Renato's solution to fix form.js at http://zone.spip.org/trac/spip-zone/changeset/4794

Another one is to use: s = this.getAttribute('action'); if (typeof(s)!='string') s = this.attributes.action.value;

One of these patches might apply to jquery.js and/or form.js

There is definitively a bug here, that doesn't let ajax calls access the "action" input value of a form.

http://jquery.com/discuss/2006-August/010153/ http://jquery.com/discuss/2006-August/010155/

Change History (5)

comment:1 Changed 13 years ago by joern

Component: ajaxcore

Your description is very irritating, but nonetheless, the problem exists. I just added a test for this: ok( $('#form').attr('action') == "formaction", 'Check for action attribute' ); It works with FF but fails in IE6.

comment:2 Changed 13 years ago by joern

Tricky one. I tried adding this to jQuery.attr:

if( elem.nodeName && elem.nodeName.toUpperCase() == 'FORM' && (name == 'action' || name == 'method') ) {
  return elem.getAttributeNode(name).nodeValue;
}

While that passes my test in IE6, Opera 9.01 fails.

Anyway: It makes more sense to add this to jQuery.attr and change form.js to use jQuery.attr.

comment:3 Changed 13 years ago by joern

Fixed in SVN for IE, Opera still fails to get the correct attribute. Any hints to to solve this for Opera are appreciated.

comment:4 Changed 13 years ago by joern

Resolution: fixed
Status: newclosed

Opera did work fine, but the test was crap. Fixed.

comment:5 Changed 13 years ago by anonymous

In the given example: <form action="url"> <input type="text" name="action" value="ok" /> </form> this.getAttribute('action') should be "ok", not "url".

That is completely wrong. getAttribute is always surposed to get the attribute of an element. form is an element, and action is an attribute of the form. this.getAttribute('method') should also return get/post and not the value of a <input name="method"/> element.

To get the value of an form element use the .val() on the corresponding element.

Note: See TracTickets for help on using tickets.