I am using following code but it is not working. Tell me if any suggestion. I want all chekboxes unchecked when I load the page. I've got the following code but it doesn't work:
window.onload = function abc() {
document.getElementsByTagName('input')[0].focus();
}
<tr>
<td>
<input type="checkbox" ID="cb1" value="29500" onclick="if(this.checked){ cbcheck(this) } else { cbuncheck(this)}" /> Laptop
</td>
<td>
<a href="#" id="a1" onmouseover="showimage('a1','laptop1');" >Show Image</a>
<img src="Images/laptop.jpg" id="laptop1" alt="" style="display:none; width:150px; height:150px;" onmouseout="hideimage('a1','laptop1');" class="right"/>
</td>
</tr>
<tr>
<td>
<input type="checkbox" ID="cb2" value="10500" onclick="if(this.checked){ cbcheck(this) } else { cbuncheck(this)}" /> Mobile
</td>
<td>
<a href="#" id="a2" onmouseover="showimage('a2','mobile1');" >Show Image</a>
<img src="Images/mobile.jpg" id="mobile1" alt="" style="display:none; width:150px; height:150px;" onmouseout="hideimage('a2','mobile1');" />
</td>
</tr>
Call this function on your page load event
function UncheckAll(){
var w = document.getElementsByTagName('input');
for(var i = 0; i < w.length; i++){
if(w[i].type=='checkbox'){
w[i].checked = false;
}
}
}
You should try
window.onload = function(){
var checkboxes = document.getElementsByTagName("INPUT");
for(var x=0; x<checkboxes.length; x++)
{
if(checkboxes[x].type == "checkbox")
{
checkboxes[x].checked = false;
}
}
}
and If you can use jQuery, you can try
$(function(){
$('input[type=checkbox]').prop("checked", false);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With