Check All Checkboxes by select single check box in java script

Check All Checkboxes by select single check box in java script

In-Trending

7 лет назад

13,297 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@rajibratankoley4082
@rajibratankoley4082 - 30.08.2020 10:25

It works thank you so much

Ответить
@vikasravidas5637
@vikasravidas5637 - 03.07.2020 18:40

<!DOCTYPE html>
<html>
<head>
<title>Multiple Selection</title>
</head>
<body>
<form action="/" method="post" name="myform">
<input type="checkbox" name="chk_all" onchange="checkall()" value=""> Select All
<hr>
<input type="checkbox" name="chk_1" value=""> Check1
<input type="checkbox" name="chk_2" value=""> Check2
<input type="checkbox" name="chk_3" value=""> Check3
<input type="checkbox" name="chk_4" value=""> Check4
<input type="checkbox" name="chk_5" value=""> Check5
<input type="text" name="name">
</form>

<script type="text/javascript">
function checkall()
{
var total_element = document.forms[0].elements.length;
//alert(total_element); //it returns no. of elements..
for (var i = 0; i < total_element; i++)
{
var elementsname =document.forms[0].elements[i].name;
//alert(elementsname); // it returns the name of elements
if (elementsname!=undefined && elementsname.indexOf('chk_')!=-1)
{
document.forms[0].elements[i].checked=document.myform.chk_all.checked;
}


}
}
</script>
</body>
</html>

Ответить
@vikasravidas5637
@vikasravidas5637 - 03.07.2020 18:39

sir, your code is working but, if we want to use more than one ( multiple chekcboxes) in table then who to apply this code

Ответить
@jsllsj9871
@jsllsj9871 - 20.08.2017 14:55

cannot find the source code? could you please post the exact link to the source code for this tutorial please thankyou

Ответить
@BhaveshRabari
@BhaveshRabari - 08.09.2016 15:15

very nice.. useful example..

Ответить