HTML form submission via XMLHttpRequest

P

patrick73

I would like to submit a standard html form using the XMLHttpRequest
object. As far as I can tell there is no easy way to do this. What I
have to do is:
1 Register an event handler on the forms submit event
2 In this handler I have to:
2.1 Prevent the default action so that the form does not submit in
the current window
2.2 text/x-www-form-urlencode all the form element name value pairs
following the rules at:
http://www.w3.org/TR/html4/interact/forms.html#submit-format
2.3 Build an XMLHttpRequest to the form action uri and then send all
the encoded elements

All this is fine, except that at:
http://www.w3.org/TR/html4/interact/forms.html#submit-format
the standard specifies that:
"If a form contains more than one submit button, only the activated
submit button is successful" and hence only this submit buttons name
value pair has to be submitted.

There does not appear to be any standard way to determine which input
submit element was active during the submit! However, the form.submit()
method knows which element was active so there must be a way (without
registering event handlers on all the input submit buttons).

IE has the unstandard document.activeElement property, is there a
standard property somewhere? Is there an equivalent to this in gecko?
 
G

goulart

Straight off the bat, what I'd do is add onclick event handler to the
submit buttons:

<input type="submit" value="Send1" onclick="formSubmit(this") />
<input type="submit" value="Send2" onclick="formSubmit(this") />

then in

function formSubmit(button) {

// add value of button clicked to what is getting sent.
//"submit" : button.value
}
 
P

patrick73

Well yes, that is how I do it at the moment, but I want to avoid that
(in my case it is not always possible). This information must be sotred
somewhere, otherwise the form.submit() method would not work. IE stores
in at least document.activeElement, but where does gecko (or standards
compliant DOM) store it?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,999
Latest member
MakersCBDGummiesReview

Latest Threads

Top