jquery checkbox and array help

Posted by sea_1987 on Stack Overflow See other posts from Stack Overflow or by sea_1987
Published on 2010-04-12T14:21:22Z Indexed on 2010/04/12 14:33 UTC
Read the original article Hit count: 264

Filed under:
|
|
|

Hi There I need to get the names and values of checkboxes that have been checked into an array name selected, I cannot for life of me get it working, below is my attempt, if someone could clrify what I am doing wrong that would be brilliant.

//Location AJAX
    //var dataObject = new Object();
    var selected = new Array();
    $('#areas input.radio').change(function(){ // will trigger when the checked status changes
        var checked = $(this).attr("checked"); // will return "checked" or false I think.
        // Do whatever request you like with the checked status
        if(checked == true) {
        /*$("input:checked").each(function() {
                selected.push($(this).attr('name')+"="+$(this).val();
            });
                alert(selected)*/
                getQuery = $(this).attr('name')+"="+$(this).val()+"&location_submit=Next";
                $.ajax({
                    type:"POST",
                    url:"/search/location",
                    data: getQuery,
                    success:function(data){
                        alert(getQuery);
                        console.log(data);
                        //  $('body.secEmp').html(data);
                    }
                });
        } else {
            //do something to remove the content here
            alert("Remove");
        }
    });

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about jquery-ajax