This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Save button with Ajax

 
Jayasri Alaparthi
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • 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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64855
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64855
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Brent Sterling
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks Brent for giving me idea as how to proceed.

with regards,
 
Mehul Wani
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64855
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • Quote
  • Report post to moderator
...or you could add id attributes to your elements.

- Brent
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic