• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to Submit data in Ajax

 
Rajendra Prakash
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends , am newbie to ajax. For example just consider one account registration -
A form contains 8 text fields with submit button. In this form second texbox contains "username " . On right side of text box there is a label box . On clilck action i need to determine user is available or not. Is it possible on clicking label or should i click
submit button.
 
Ankit Garg
Sheriff
Posts: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So all that you need to know is whether there's a value in the username field or not when a checkbox is clicked?? If yes then this has nothing to do with struts and I'll move it to the HTML and javascript forum where you might get a better reply.

If I'm understanding it right, then its not very tough to do. On the onclick event of the checkbox, you need to check the value property of the textbox using its ID. Like if the username textbox has the ID user_name, then the onclick even will just check
 
Rajendra Prakash
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I mean onclicking checkbox(action) can i send request to server or should i click submit button to send request to server.
 
Ankit Garg
Sheriff
Posts: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I still can't understand what you want to do. You want to send an Ajax request, now whether you send it on click of a checkbox or a button depends upon what you want to do. submit button by default posts back the page instead of making an Ajax call. What exactly do you want to do is not clear...
 
Rajendra Prakash
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can i send a request to server on clicking check box. is it possible
 
Ankit Garg
Sheriff
Posts: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can i send a request to server on clicking check box. is it possible

Yes it is possible using the onclick event of the checkbox...
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64617
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please take the time to choose the correct forum for your posts. This forum is for questions on Servlets. For more information, please read this.

This post has been moved to a more appropriate forum.
 
Anbarasu Aladiyan
Ranch Hand
Posts: 182
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

1. On click event of labels call a java script function
2. In that java script function, create an XMLHttpRequest object
3. Create a post string that needs to send to servlet calss. In your case "user name"
4. By using XMLHttpRequest object's 'open','setRequestHeader','send' methods send the request to the servlet
5. Do your business logic in servlet and send the output to java script by write/print/JSON techniques.(in your case 'true/false' or exists/available)
6. In java script check for readyState(ie readyState ==4) then use XMLHttpRequest object.responseText to get the result that sent from servlet.

Regards,
Anbarasu
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic