Bug Tracker

Opened 15 years ago

Closed 12 years ago

Last modified 11 years ago

#3113 closed bug (duplicate)

unexpected attr behavior on form with input element named 'action'

Reported by: rryan Owned by: flesler
Priority: low Milestone: 1.3
Component: attributes Version: 1.2.6
Keywords: attr Cc:
Blocked by: Blocking:

Description

Given the following form:

<form action="someaction"> <input type="hidden" name="action" value="somevalue"/> </form>

If you have the dom element for the form, 'f'.

f.action = "foo", sets the value of the input element, not the action attribute on the form.

f.setAttribute("action","foo") sets the action attribute on the form tag.

In jQuery, if you say $("#form").attr("action","foo"), it actually sets the input element named action to 'foo', instead of setting the attribute on the form tag. Is this a bug? 'attr' would seem to imply the functionality of 'setAttribute', not this magic 'action' accessor on the dom element.

Thanks for all your hard work!

Attachments (1)

attr-form.diff (2.5 KB) - added by flesler 15 years ago.
Imported from #2959.

Download all attachments as: .zip

Change History (14)

comment:1 Changed 15 years ago by flesler

need: ReviewPatch
Owner: set to flesler
Status: newassigned

This was already spotted, we do have a solution in mind. We'll review this for 1.3.

Changed 15 years ago by flesler

Attachment: attr-form.diff added

Imported from #2959.

comment:2 Changed 15 years ago by mw44118

Slightly related: it seems impossible to select a form by using the action attribute; e.g.,

<form action="x"> </form>

$("form[action='x']") will return an empty set of nodes.

comment:3 Changed 14 years ago by dmethvin

Also applies to "method", per #4039.

comment:4 Changed 14 years ago by malsup

This probably applies to any form attribute. I've confirmed action, method, and target. I suspect others will fall into this category as well, such as enctype and accept. Perhaps even coreattrs like title.

comment:5 Changed 14 years ago by hakre

I was able to help myself by using

$("#formid").get(0).setAttribute("action", action);

where action is a variable containing the action value to be set.

Anyway, this is a Bug I would love to see fixed because the jQuery function does not what it is supposed to be. Since jQuery adds a Layer on the standard Javascript Implementation, it should cirumvent the Problem(s) that the Browsers Javascript Implementation has in this case.

comment:6 Changed 13 years ago by dmethvin

Also applies to id per #1169.

comment:7 Changed 13 years ago by dmethvin

Component: coreattributes

comment:8 Changed 13 years ago by webapp

I guess this is directly related : you can't (at least with Firefox 3.6) select a form by any of its attribute, if any field in the form has the name of the attribute.

For an exemple, if a form has an attribute 'autosubmit="yes"' and a input whose name is "autosubmit", $('form[autosubmit=yes]') doesn't select it. $('form[autosubmit]') selects it, though (the value of the input is probably used instead of the value of the attribute).

comment:9 Changed 13 years ago by dmethvin

#7212 is a duplicate of this ticket.

comment:10 Changed 13 years ago by Eddie Monge

Test case for the attr not being set: http://jsfiddle.net/eTiger13/j35Xc/2/ Similiar to this but without the input having the name of action: http://jsfiddle.net/eTiger13/j35Xc/3/

Only affects FF

comment:11 Changed 12 years ago by Timmy Willison

This is fixed with the attrhooks updates.

Version 0, edited 12 years ago by Timmy Willison (next)

comment:12 Changed 12 years ago by Rick Waldron

Priority: minorlow
Resolution: duplicate
Status: assignedclosed

comment:13 Changed 12 years ago by Rick Waldron

Duplicate of #7212.

Note: See TracTickets for help on using tickets.