I want to do checkall functionality using javascript when i click on submit button all checkbox should be checked.However they all checkbox are checked but they just checked for a few second. i don't know where i'm wrong. my html
<form method="post" name="myform">
<input type="checkbox" name="h" value="1" id="g">Reading<br/>
<input type="checkbox" name="h" value="2" id="g">php<br/>
<input type="checkbox" name="h" value="3" id="g">playing<br/>
<input type="checkbox" name="h" value="4" id="g">Gaming<br/>
<input type="checkbox" name="h" value="5" id="g">Coding<br/>
<!--<input type="radio" name="gen" value="male">Male<br/>-->
<!--<input type="radio" name="gen" value="female">Female<br/>-->
<input type="submit" name="sub" value="submit" onclick="checkall(document.myform.h)" >
</form>
my javascript
<script type="text/javascript">
function checkall(chk)
{
var i;
//alert(chk);
//var gend=document.myform.gen.value;
//alert(gend);
for(i = 0;i < chk.length; i++)
{
chk[i].checked = true;
//return true;
}
}
</script>
Aucun commentaire:
Enregistrer un commentaire