473,394 Members | 1,703 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

HTML form submission via XMLHttpRequest

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?

Jul 13 '06 #1
2 3472
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
}

Jul 13 '06 #2
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?

goul...@gmail.com 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
}
Jul 13 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Shannon | last post by:
Hi everyone, I am trying to post some data to a form using the XMLHTTP object, and have run into a problem trying to find the proper location of the receiving page. The form points to a...
5
by: Richard Cornford | last post by:
I am interested in hearing opinions on the semantic meaning of FORM (elements) in HTML. I have to start of apologising because this question arose in a context that is not applicable to the...
3
by: Chris Smith | last post by:
Good morning, Is there a good way to use JavaScript to send a form submission, but get back the response as a string, rather than loading it into a page? I could write the code to send the...
9
by: Phil_Harvey | last post by:
I am redoing my website and trying to get it to do something more exciting using Javascript. I did normal Java at university and code at work in VB.NET. I have got reasonably far into what I want...
7
by: pamelafluente | last post by:
The precious input given by Laurent, Martin, Benjamin about XMLHttpRequest in Javascript, has made me think that perhaps I could improve what I am currently doing by using Ajax. Let's make it...
3
by: Niall | last post by:
The short version: how does one get Javascript to abort a form submission/page load half way through? Long version: I have a page, the guts of which can be summarised as: <script>
5
by: Otto Wyss | last post by:
It's possible to declare inbut fields outside of a form, is it possible to post these values to the server? E.g. attach them to the posted form? O. Wyss
2
by: anusha.vempati9 | last post by:
Hi All, I am calling a cgi file from a perl module. The cgi file contains the HTML form and some HTML fields(like check boxes). In my logic, I am trying to submit the form and calling the same...
5
by: thatcollegeguy | last post by:
Below are my 3php and 2js files. I create a table using ajax/php and then want to change the values in the tables add(+ number for teamid) id's for each specific td in the table. I don't know...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.