2

I wrote a jquery code to send values to a php file

$('#def_formSubmit').live("click",function(){

        var query_string = '';
                    
                    $("input[@type='checkbox'][@name='assotop']").each(
                        function()
                        {
                            if(this.checked)
                            {
                                query_string += "&assotop[]=" + this.value;
                            }
                        });

    
    var def_tags = $("#tags").val();
    
    var dataString = 'def_tags='+ def_tags + query_string  ;

    $.ajax({
        type: 'POST',
        url: 'post.php',
        data: dataString,
        cache: false,
        beforeSend: function() {
            $("#QRresult").html("<img src='images/loading.gif' />");
        },
        success: function(data5) {
            $("#QRresult").html(data5);
        }
    });
    return false;
});
    

But it does not work and does not sendi checkbox values to my php file.

I think this way of getting checkbox values is a old approach and not working for jquery 1.4.

2 Answers 2

3

Remove the @ from your selector. This changed as of 1.3

$("input[@type='checkbox'][@name='assotop']").each(

should be:

$("input[type='checkbox'][name='assotop']").each(

You could also do:

$("input:checkbox[name='assotop']").each(

EDIT: Added input to the selector as noted by @lonesomeday.

EDIT: I guess I'd use the one with input[type='checkbox'] so that querySelectorAll will be used in browsers that support it.

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

8 Comments

perhaps use input:checkbox too?
+1, but input:checkbox will be much quicker, since it doesn't have to select every element and then check it for being an input element.
@lonesomeday - I thought :checkbox took care of that. Perhaps I'm mistaken. I'll update. EDIT: Looking at the docs, I see you're correct. Thanks. :o)
@lonesomeday: Why not just use :checkbox which is much faster, you don't need input there with it.
@Sarfraz - From the docs: $(':checkbox') is equivalent to $('*:checkbox'), so $('input:checkbox') should be used instead.
|
1

Try this code:

$(document).ready(function(){
    $("#selectAll").change(function(){
        $(".sports").prop('checked', ($(this).is(':checked')));
    });
    $(".sports").change(function(){
        $("#selectAll").prop('checked', false);
    });
});

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.