0

I am having one of those 'moments' where I am just confused.

I have a form, with a checkbox group. There are 12 checkboxes. They are set up as follows:

<input type="checkbox" id="search_shape1" name="search_shape[]" value="BR" /> 
<input type="checkbox" id="search_shape2" name="search_shape[]" value="AS" /> 

etc etc...

Now, instead of submitting them via a submit button, I am using jQuery to pass all the form variables (this form also includes 5 jQuery.ui sliders. The code I am using is below:

    $(function() {
    $("#epds").bind('submit',function() {
        var search_shape = $('#search_shape').val() || [];
        $.post('catalog/view/theme/emmaparker/template/information/db_query.php',{search_shape:search_shape}, function(data){
            $("#search_results").html(data);
        });
        return false;

The problem is, on my processing page (db_query.php), it NEVER gets the results of the checkbox. It does get all of the sliders inputs (input type=textbox.. I pulled all of those out of the above code). I have tried pretty much everything, and I am just confused. I have tried putting "search_shape" alone as the name, "search_shape[]" as the name, everything. It just won't pass a value.

On the db_query page, I have tried outputting the value in several ways. I have tried print_r, simple echo, setting a value as an explicit array and then setting that variable to the post result, etc etc etc.

I am at a loss. Can anyone smack me upside the head and let me know what I'm doing wrong? I'm sure it is something simple, like I am not passing the value in the jQuery properly or something.

Thanks, Derek

  • Simmilair to http://stackoverflow.com/questions/4813219/jquery-checkbox-value and http://stackoverflow.com/questions/786142/how-to-retrieve-checkboxes-values-in-jquery? By the way, googling for your question gives a lot of topics on stackoverflow... Try the search function – Dennis Hunink May 11 '12 at 14:13
  • I certainly have searched and none of those relate to my problem. All I simply want to do is pass the array of a checkbox group so that I can use it in a SQL "in" statement. I don't need to post it in a textarea or see if it IS checked. – Derek Reidy May 11 '12 at 16:04

1 Answers1

0

How about something like this? Haven't tested it but it should work like this.

var group = new array();
$.each($("input[name='search_shape[]']:checked"), function() {
  group.push($(this).val());
});
Dennis Hunink
  • 583
  • 2
  • 7
  • 21