• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Save button with Ajax

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Friends,
I am using struts MVC framework, where the data is taken from dao in action and kept in form for save process but the page is refreshing but, I want the save button to be an ajax call can some one guide me as how to proceed.


with regards,
Bhargavi.
 
Sheriff
Posts: 67682
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you already know Ajax? Your post is too vague to give any concrete advice.
 
Jayasri Alaparthi
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,
I know basics of Ajax, so can you guide me as how to write save button.

with regards.
 
Bear Bibeault
Sheriff
Posts: 67682
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You haven't provided many details. What type of button? If it's a submit button, you can hijack the form submission. If it's not, then an event handler for click can be established on the button.
 
Jayasri Alaparthi
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The save button which I need to write ajax functionality has to submit the form. Can you give any url or sample for this.
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First hit from a Google search for "submit form ajax": http://www.captain.at/howto-ajax-form-post-request.php

- Brent
 
Jayasri Alaparthi
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Brent for giving me idea as how to proceed.

with regards,
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bhargavi,

Submitting a form using AJAX is easy.

Only thing is you will need to read all the form field values manually(since you are using AJAX and not submitting the form) using
document.getElementById(fieldName).value and appending name and value for each field to the AJAX url.

Note: document.getElementById(fieldName).value doesn't work in Firefox
instead you can use document.forms[0].fieldName

This all can be using a javascript function and calling that function on the onclick event of button.
Hope this helps.
[ March 19, 2008: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Sheriff
Posts: 67682
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

document.getElementById(fieldName).value doesn't work in Firefox

Of course it does. As long as you correctly pass the element id to the function.
 
Brent Sterling
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Note: document.getElementById(fieldName).value doesn't work in Firefox


You are probably confused by what is basically a bug in IE. If IE does not find an element with the given id it will look for an element with a name that matches the given id. Other browsers implement the getElementById method correctly.

- Brent
 
Mehul Wani
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Brent,

I tried it on Firefox v1.5. I have javascript code having lot of document.getElementById(). Now, when I open an url in Firefox and parallely open the javascript console, I see a lot of errors and warnings on the console.

If instead of document.getElementById() one uses document.forms[0].fieldName
works fine with firefox.

Thanks for the reply and correct me if I'm wrong.
 
Brent Sterling
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
...or you could add id attributes to your elements.

- Brent
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic