views:

106

answers:

1

I have in my document 2 checkbox arrays. One is engines[] and one is searchId[].

$("input:checkbox[@name='searchId[]']:checked").each(function() i use this to capture all the values from the searchId[] checkboxes (only if checked). $("input:checkbox[@name='engines[]']:checked").each(function() same thing for engines

the problem is that it the selector gets all the checked checkboxes in the document regardless of their name. How can I make it get only the array I wish to get?

some code for a better understanding:

$("#startSearch").live("click", function(event){ //event.preventDefault(); $("input:checkbox[@name='searchId']:checked").each(function(){

                    $.getJSON("startsearch.php",{searchId: $(this).val()},function(data){
                        alert($(this).val());
                        $('#status_' + $(this).val()).text(data.status);
                        $('#results_' + $(this).val()).text(data.results);
                        $('#date_' + $(this).val()).text(data.date);
                        $('#totalResults_' + $(this).val()).text(data.totalResults);
                    });
                });
            });

$("#submit").click(function(event){ event.preventDefault();

                $("input[@name='engines[]']:checked").each(function(){

                    $.getJSON( "addsearch.php", { inputString: $('#inputString').val(),searchString: $('#searchString').val(), engine: $(this).val() }, function(data){
                        //$('#searchTable tbody tr:first').empty();
                        var row = '<tr><td><span id ="status_'+data.id+'">'+data.status+'</span></td>'+
                            '<td>'+data.search+'</td>'+
                            '<td>'+data.category+'</td>'+
                            '<td>'+data.engine+'</td>'+
                            '<td><span id = "results_"'+data.id+'">0</span></td>'+
                            '<td><span id ="date_'+data.id+'">'+data.date+'</span></td>'+
                            '<td><span id ="totalResults_'+data.id+'">0</span></td>'+
                            '<td style="width: 96px;"><div class="actions"><ul>'+
                            '<li><input class="radio" name="searchId[]" type="checkbox" value="'+data.id+'" /></li>'+
                            '<li><a class="action1" href="#">1</a></li>'+
                            '<li><a class="action4" href="#">4</a></li>'+
                            '</ul></div></td>';
                        $('#searchTable tbody').after(row);
                    });
                });

            });
        });
+1  A: 
  1. The @attr selectors were completely removed on jQuery 1.3, if you are using a jQuery version > 1.2, simply remove the @ sign from the selector.
  2. The [ and ] characters need to be double escaped.

    $("input:checkbox[name='searchId\\[\\]']:checked").each(function () {
      //..
    });
    

From the docs:

In jQuery 1.3 [@attr] style selectors were removed (they were previously deprecated in jQuery 1.2). Simply remove the '@' symbol from your selectors in order to make them work again.

The full list of characters that need to be escaped: #;&,.+*~':"!^$[]()=>|/

CMS