Return an array of values from toggled images in jquery

I am using a jquery post to return an xml dataset. I was originally using drop down form controls to filter the data as it was returned.

Now I want to be able to display a list of manufacturer icons and then have the user click on those to toggle them on and off.

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

Currently I have the toggle code in place so that the image just gets a box around it when it is clicked. I am also setting the ALT attribute with a value. I want to be able to gather all the alt attribute that have values and pass them to my 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()}, <----- I need to replace this section of code
    function(xml) {
        convertXML(xml);
        $("#wrapper").empty();
        $('#results').html("Your Product was not found");
    },"xml")

}

Ultimately the value that gets passed to the manufactuer variable is simply a comma separated list of values such as ara,sho,sha,ara

Does anybody have any thoughts on this please. I have tried using the .each() method and have managed to get it to alert all the positive values but I cannot concatenate them into a string.

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

As always help is much appreciated.

Cheers Graham

Answers


try this..

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

jsFiddle to show uses of push and and join

http://jsfiddle.net/jCdpf/


Need Your Help

how can i know that a stack is empty if i use this method to pop elements?

c stack

I'm trying to implement a stack in C using singly linked lists, it all works fine as long as the stack is non-empty. Once empty my pop method never detects that its empty but gives some random valu...

What is the best way to get a content object's position in the parent? Plone 4

indexing position plone catalog plone-4.x

I am traversing folders with content items within them. I use the portal_catalog to get brains searched on certain paths. The brains have access to metadata, and brain.getObject() will return the

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.