2

What wrong with the my code. When I click on the checkbox, nothing happen

$(document).ready(function(){
     $('input:checkbox[name=drawingNo]').click(function(){alert('I am here');});            
});  
...
<body>
    <form>
        <input type="checkbox" name="drawingNo" value="1"> 1 <br>
        <input type="checkbox" name="drawingNo" value="2"> 2 <br>
        <input type="checkbox" name="drawingNo" value="3"> 3 <br>
        <input type="checkbox" name="drawingNo" value="4"> 4 <br>
    </form>
</body>

EDIT: The above code worked fine. What happen to me is that, the tag <input type="checkbox"> are generated by some other script, so when document.ready() fire up, it cant register click event to checkbox, since these checkbox are not really there yet. So to fixed it: change .click() into .live('click', function(){...})

4 Answers 4

4

Your selector is wrong..

The below is the best format

$(document).ready(function(){
 $("input[name='drawingNo']").live('click', function(){
 alert('I am here');
 });            
});
Sign up to request clarification or add additional context in comments.

1 Comment

check the way the selector is formatted " $("input[name='drawingNo']") " and the live event added
1

It works fine for me in IE, FF and Chrome.

Comments

1

Use $.fn.live ...

$('input:checkbox[name=drawingNo]').live('click',function(){
   alert('I am here');
});

Comments

0

try removing ':checkbox' so that it looks like:

$('input[name=drawingNo]').click(function(){alert('I am here');});

any better?

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.