ajax - Return an array of values from toggled images in jquery -


i using jquery post return xml dataset. using drop down form controls filter data returned.

now want able display list of manufacturer icons , have user click on toggle them on , off.

$('#sho').click(function() {     $(this).toggleclass('highlight');     if ($(this).hasclass('highlight')){             $(this).attr('alt','sho');             alert(manufac);     } else {             $(this).attr('alt','');     }}); 

currently have toggle code in place image gets box around when clicked. setting alt attribute value. want able gather alt attribute have values , pass them jquery post.

function loadxml(so) { <!-- clothing version --> timestamp = math.round(new date().gettime() / 1000);  $("#wrapper").html('<div id="load"><img src="http://static.phmotorcyclescom.dev/images/loading.gif" alt="loading" align="center"  /></div>'); $("#results").empty(); $.post("http://www.phmotorcycles.current/supportscripts/clothingxml.asp",{       productgroup: "hel",       sortorder: so,     qt: "group",     ts: timestamp,     manufacturer:$("input:checkbox[name='man[]']:checked").map(function() {         return $(this).val();     }).get()}, <----- need replace section of code     function(xml) {         convertxml(xml);         $("#wrapper").empty();         $('#results').html("your product not found");     },"xml") 

}

ultimately value gets passed manufactuer variable comma separated list of values such ara,sho,sha,ara

does have thoughts on please. have tried using .each() method , have managed alert positive values cannot concatenate them string.

$('img').each(function(){             var id = $(this).attr("id");             var altval = $(this).attr("alt");             if (altval != '') {                 alert($('img#' + id).attr('alt'));             }         }); 

as appreciated.

cheers graham

try this..

manufacturer : function() {     var ar= new array();      $("img.highlight").each(function(){      ar.push($(this).attr("alt"));     });    return ar.join(","); } 

jsfiddle show uses of push , and join

http://jsfiddle.net/jcdpf/


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -