I am working in wordpress. And I have created one multiple selected dropdown.
My jQuery code is like this:
jQuery('#int_btn').click(function(){
//var int_val = "";
var int_val = [];
var int_text = [];
var selected = [];
jQuery( ".tole_int option:selected" ).each(function() {
//int_val += jQuery( this ).text() + " ";
int_val.push(this.value);
int_text.push(this.text);
});
//jQuery( ".int_div" ).text( int_val );
jQuery.ajax({
url:"<?php echo site_url().'/interests-with-stars'; ?>",
data:{int_val: int_val,text:int_text}
}).done(function(data){
//jQuery('.int_div').html(data);
});
});
Now,when I click on button then I have to stored selected value in an array as key and value.Morevover, i want to pass that array in post.So what jQuery I have to write?
Better you use this way, try this :
Ajax data should be:
DEMO – see console