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 Answer 1

5
  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: #;&,.+*~':"!^$[]()=>|/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.