473,326 Members | 2,102 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,326 software developers and data experts.

submit a form in the background using ajax

Is it possible to submit a form using ajax?

I have a form with sever inputs and when submited, it writes the input values in a jsp file. I would like to submit the form using ajax in the background. I don't want the user to be directed to that page.

the only way I thought I could do it is in ajax is to call the jsp with the parameter
something like calling
req.open("GET","insert.jsp?param="document.form.in put.value1+"&param2=...,true)

but I would rather try to submit the form. it would be easier. So can anyone tell me how it could be done?

10x in advance
Mar 7 '08 #1
1 3435
gits
5,390 Expert Mod 4TB
i doubt that ... but you coud just write a function like the following that returns you the query-string:

Expand|Select|Wrap|Line Numbers
  1. /**
  2.  * example for text, hidden, select nodes and only when they
  3.  * are direct childs -> may be that has to be extended/adapted
  4.  */
  5. function get_params(form) {
  6.     var c   = form.childNodes;
  7.     var qs = '?';
  8.  
  9.     var node_types = { text: 1, hidden: 1, select: 1 };
  10.  
  11.     for (var i = 0, n; n = c[i]; i++) {
  12.         if (n.type in node_types) {
  13.             qs += n.name + '=' + n.value + '&';
  14.         }
  15.     }
  16.  
  17.     qs = qs.replace(/[&]$/, '');
  18.  
  19.     return qs;
  20. }
  21.  
so you could now use something like this:

Expand|Select|Wrap|Line Numbers
  1. req.open('GET', 'insert.jsp' + get_params(document.forms[0]), true);
kind regards
Mar 7 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Eric | last post by:
Hey Everyone.. I have a form that has approximately 7 text fields and 1 checkbox. Generally when this form is submitted(to itself BTW) it works fine, however, when the checkbox is only field...
1
by: jim whitaker | last post by:
I followed this tutorial, and I have it working. http://www.webpasties.com/xmlHttpRequest/ My question is this: After an AJAX form receives it's data from the server, how could i then submit...
4
by: d3vkit | last post by:
I have a form on my page, and some javascript which uses ajax to submit the form, and then opens the new page in a div using ajax so there is no refresh. This works fine. But the problem is this: all...
4
by: vunet.us | last post by:
Hi all, I am converting my app to AJAX-based. I have a form that submits some data including images. When I use AJAX XmlHttpRequest I am unable to submit the form with...
2
by: John Murtari | last post by:
Folks, We are working on upgrading a web based application that allows the user to type quite a long essay and then submit it to the web site for processing. Occasionally, the user will lose...
10
by: The Natural Philosopher | last post by:
I am coding up a bit of javascript stuff, and have managed to stumble my way through most of what I want.. But this one has got me stumped. I call submit() and get a javascript error 'Submit...
6
by: dmorand | last post by:
I'm having a little trouble with my ajax. I can see my results in IE, but not firefox. I'm assuming I'm missing some syntax somewhere. alert("Test " + results + testing); returns the values in...
2
by: ravisuguna | last post by:
Hi, I have a php page which has some checkboxes ,textfields and values.If I select a checkbox ,a particular value will be displayed in a textfield.I have a "go"button in the same page.I want the...
7
by: Nalum | last post by:
Hello all, I've had a look around but couldn't find an answer to my question. I'm trying to submit a form using the javascript .submit() function but it doesn't seem to want to work. I'm using Ajax...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.