• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1860
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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