views:

19

answers:

2

I have an application that generates a element with an 'action' attribute. I need to change the value of the action attribute, but it's not possible to do that. However it is possible to add another 'action' attribute before the generated one thusly:

This seems to work for IE. I'd like to know if this behavior is defined in the w3c standards, and whether I can rely on browsers choosing the first action attribute. I searched the standards docs a bit but couldn't determine the rule for repeating attributes.

Thanks.

+2  A: 

The spec says there can only be one action attribute on a form.

This makes sense, as the action attribute specifies the page the form data will be posted to and posting it to two different pages makes not sense (how are you to see the results from more than one page?).

If you look at the DTD fragment defining the FORM element from the spec:

<!ELEMENT FORM - - (%block;|SCRIPT)+ -(FORM) -- interactive form -->
<!ATTLIST FORM
  %attrs;                              -- %coreattrs, %i18n, %events --
  action      %URI;          #REQUIRED -- server-side form handler --
  method      (GET|POST)     GET       -- HTTP method used to submit the form--
  enctype     %ContentType;  "application/x-www-form-urlencoded"
  accept      %ContentTypes; #IMPLIED  -- list of MIME types for file upload --
  name        CDATA          #IMPLIED  -- name of form for scripting --
  onsubmit    %Script;       #IMPLIED  -- the form was submitted --
  onreset     %Script;       #IMPLIED  -- the form was reset --
  accept-charset %Charsets;  #IMPLIED  -- list of supported charsets --
  >

You will see that the action attribute is a. required, b. does not have a multiple specifier, meaning it should only exist once.

It is probably only by chance that this works in IE. The behaviour is not defined, and another browser might either choke on this input or decide to pick a random action attribute.

Oded
A: 

+1 for Oded's answer :D

BTW, if you have to edit the original action, maybe you could try using javascript:

$("#your_form").attr("action", "something_else"); // in jQuery
PeterWong