Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > HTML form submission via XMLHttpRequest

Reply
Thread Tools

HTML form submission via XMLHttpRequest

 
 
patrick73
Guest
Posts: n/a
 
      07-13-2006
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/...#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/...#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?

 
Reply With Quote
 
 
 
 
goulart@gmail.com
Guest
Posts: n/a
 
      07-13-2006
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
}

 
Reply With Quote
 
 
 
 
patrick73
Guest
Posts: n/a
 
      07-13-2006
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?

(E-Mail Removed) wrote:
> 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
> }


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FAQ 9.9 How do I automate an HTML form submission? PerlFAQ Server Perl Misc 0 03-16-2011 10:00 PM
Passing data via XMLHTTPRequest... How do YOU do it? Noozer ASP General 7 04-15-2006 09:19 AM
POSTing html via XmlHttpRequest Slipperman Javascript 2 08-09-2005 11:16 PM
XMLHttpRequest and submission charset lio Javascript 1 05-09-2005 10:57 AM
Form Submission: Final URL that has form options included ?? Jared Javascript 5 07-10-2003 10:33 AM



Advertisments