Rene Zammit
Rene Zammit

Reputation: 1151

Jquery setting up a default value for checkbox on load or page

On load of the page I want to set it to FALSE immediately. How I can do that please? thanks

Upvotes: 1

Views: 9044

Answers (6)

Niranjan Singh
Niranjan Singh

Reputation: 18290

Check .prop() and .attr() function and take an idea from these code snippets to implement your functionality.

 $(document).ready(function(){

    $(".myCheckbox").prop("checked", false);  // select by css class

    or  

   $("#myCheckbox").prop("checked", false);   // select by checkbox id
    });

or

$('.myCheckbox').removeAttr('checked')

If you want to uncheck all checkbox on your page then try this:

$(document).ready(function(){   
    $("input[type='checkbox']").removeAttr('checked')   
})

check these links for more details

Setting "checked" for a checkbox with jQuery?

set checkbox from checkboxlist to uncheck using jquery

Upvotes: 0

Akhil Thayyil
Akhil Thayyil

Reputation: 9403

Check the answer in Fiddle it will make check box selected randomly

To make it false, u can do

$(document).ready(function(){
$("input[name='checkbxName']").removeAttr("checked");
})

Upvotes: 0

Distdev
Distdev

Reputation: 2312

$('#checkboxId').removeAttr('checked');

Upvotes: 0

jabclab
jabclab

Reputation: 15042

$(document).ready(function () {
    $("#myCheckbox").prop("checked", false);
});

Upvotes: 0

Darin Dimitrov
Darin Dimitrov

Reputation: 1038780

$(function() {
    $('#id_of_your_checkbox').removeAttr('checked');
});

Upvotes: 2

Emre Erkan
Emre Erkan

Reputation: 8482

You can execute methods when DOM is ready with .ready() and you can change value of a checkbox with .prop() like this;

jQuery(function($) {
    $('#id_of_checkbox').prop('checked', false);
})

For this example you have to give an id (id_of_checkbox) to your checbox.

Upvotes: 1

Related Questions