• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2301
  • Last Modified:

how to send multiple select box values using Jquery ajax ?

I have a select box whose name="item0_cid0".
I create more select boxes with different names e.g    "item1_cid0" , "item2_cid0" , "item3_cid0" and  so on dynamically when the user clicks Add more button.


Now, I want to send all   selected values to servlet using jquery  load (http://api.jquery.com/load/)

how do I construct the url string for load  so that I can send all the selected values to servlet ?
0
cofactor
Asked:
cofactor
  • 6
  • 6
  • 2
2 Solutions
 
CEHJCommented:
Try http://api.jquery.com/serialize/ on the form with those elements in it
0
 
cofactorAuthor Commented:
I need jquery ajax call without a form.  I want to send only select box values.



0
 
CEHJCommented:
Well you can use serialize directly on the controls themselves afaik
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
chaitu chaituCommented:
$(document).ready(function() {  

var data = {};
$("#add").click(function ()
{
$("select").each(function(el) {
                        alert($(this).val())
                    data[$(this).attr("name")] = $(this).val();
                        
            });

      $.ajax({
             type: 'POST',
             url:  url,
             data: data,
                              
             success: function(msg){              
                  
            }  
      });

     });
      
      


 });
0
 
cofactorAuthor Commented:
>>>data[$(this).attr("name")] = $(this).val();

I have two more hidden field . I want to send them as well.

How do I add that ?
0
 
chaitu chaituCommented:
two more hidden field  of textboxes or select boxes.

$("input:hidden,select").each(function(el) {
0
 
cofactorAuthor Commented:
I have two queries on your comment.

Q1:
Can we get the url string from the above data ?

var urlStr=data.toUrlString(); //  something like this ?  Need an equivalent stuff to get the url String

Q2:
I have the select boxes and hidden fields under a DIV whose id is "dataDiv"  .  I would like to search  fields from that DIV only.

Is this correct syntax ?  $("#dataDiv input:hidden,select").each(function(el) {
0
 
chaitu chaituCommented:
YES
0
 
cofactorAuthor Commented:
you did not answer Q1 . Could you please respond to that.

Is there any way I can get a url string from data ?
0
 
cofactorAuthor Commented:
comments ?
0
 
chaitu chaituCommented:
 type: 'POST',
             url:  url,
             data: data,

what do u do with urlstring.

u can pass url like this;

url:"ex.jsp" or "./actionservlet"
data:data

this data u can access in jsp or in servlet like this

request.getParameter("item1_cid0");
0
 
cofactorAuthor Commented:
>>>what do u do with urlstring.

I'm using  jquery .load()  . This takes url  data string. This does not take data.
0
 
chaitu chaituCommented:
0
 
chaitu chaituCommented:
if u want url in data do like this .

   data["url"] = "ex.jsp";

function contentDisp()
{
$.ajax({
url : data["url"],
success : function (data) {
$("#contentArea").html(data);
}
});
}
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now