I'm trying to create an event handler (jQuery) that will pick all elements of specific class, each unique ID value, post json array, loop through php, finally update view.
I have no problem with selecting one instance.
**Mostly looking how to create the array of id,value to pass for processing.
Thank You
You can do something like this (As a strting point):
$('.class').each(function(){
// do somthing with $(this)
});
Of course, if you post some more details, I can expand on this.
This snippet will give you an array of the ids of the elements with class myclass:
var id_array = $.map($(".myclass"),function(el){return el.id;});
You can then send the array to your server as JSON, or as a comma separated string, or any other way you want.
To get an array of all selected elements
var elArray = $('.classToSelect').get();
After this you may use
$.each(elArray, function(el){
var id = el.id;
var value = el.value;
//code goes here
}
A small plugin script from http://code.google.com/p/jquery-json/ is perfect for JSON encoding and decoding:
var postdata = $.toJSON(elArray);
generates a well formatted JSON string.