Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting all checkboxes.. 1

Status
Not open for further replies.

snowboardr

Programmer
Feb 22, 2002
1,401
PH
How do I select all checkboxes that have the same name? (For each record there is a checkbox) www.vzio.com
ASP WEB DEVELOPMENT



 
HTML code for a checkbox to be checked is:
<input type=checkbox name=chk1 id=chk1 checked>


I don't know if I understand you correctly or you posted this in the wrong forum.

Do you want the user to be able to click a select all button and give a true checked property to all checkboxes?

<input type=checkbox name=chk1 id=chk1>
<input type=checkbox name=chk1 id=chk1>
<input type=checkbox name=chk1 id=chk1>
<input type=checkbox name=chk1 id=chk1>
<input type=checkbox name=chk1 id=chk1>
<input type=checkbox name=chk1 id=chk1>


<script>
var i = 0;
objCheck = chk1
for(i=0;i<objCheck.length;i++){
objCheck.checked = true;
}
</script>
 
I want them to check one checkbox, and select all checkboxes with the same name..

www.vzio.com
ASP WEB DEVELOPMENT



 
This works only in IE:

<input type=checkbox name=chk1 id=chk1 onclick=&quot;checkall(this);&quot;>
<input type=checkbox name=chk1 id=chk1 onclick=&quot;checkall(this);&quot;>
<input type=checkbox name=chk1 id=chk1 onclick=&quot;checkall(this);&quot;>
<input type=checkbox name=chk1 id=chk1 onclick=&quot;checkall(this);&quot;><br>
<input type=checkbox name=chk2 id=chk2 onclick=&quot;checkall(this);&quot;>
<input type=checkbox name=chk2 id=chk2 onclick=&quot;checkall(this);&quot;>
<input type=checkbox name=chk2 id=chk2 onclick=&quot;checkall(this);&quot;>
<input type=checkbox name=chk2 id=chk2 onclick=&quot;checkall(this);&quot;>
<input type=checkbox name=chk2 id=chk2 onclick=&quot;checkall(this);&quot;>


<script>
function checkall(objCheck) {
var intTmp = 0;
var blnChecked = objCheck.checked;
objCheck = eval(objCheck.name);
for(intTmp =0;intTmp<objCheck.length;intTmp++){
objCheck[intTmp].checked = blnChecked;
}
}
</script>


Have to find a way to get arround the eval, this does not work in mozilla
 
Thats ok, its going to be used in a control panel, IE will required. www.vzio.com
ASP WEB DEVELOPMENT



 
This works both ways though:

<input type=checkbox name=chk1 id=chk1 onclick=&quot;checkall(this);&quot;>
<input type=checkbox name=chk1 id=chk1 onclick=&quot;checkall(this);&quot;>
<input type=checkbox name=chk1 id=chk1 onclick=&quot;checkall(this);&quot;>
<input type=checkbox name=chk1 id=chk1 onclick=&quot;checkall(this);&quot;><br>
<input type=checkbox name=chk2 id=chk2 onclick=&quot;checkall(this);&quot;>
<input type=checkbox name=chk2 id=chk2 onclick=&quot;checkall(this);&quot;>
<input type=checkbox name=chk2 id=chk2 onclick=&quot;checkall(this);&quot;>
<input type=checkbox name=chk2 id=chk2 onclick=&quot;checkall(this);&quot;>
<input type=checkbox name=chk2 id=chk2 onclick=&quot;checkall(this);&quot;>


<script>
function checkall(objCheck) {
var intTmp = 0;
var blnChecked = objCheck.checked;
objCheck = document.getElementsByName(objCheck.name)
for(intTmp =0;intTmp<objCheck.length;intTmp++){
objCheck[intTmp].checked = blnChecked;
}
}
</script>
 
That script doesnt seem to work. But I got around doing it this way, I just added a checkbox with &quot;Clear all records&quot; by it and did it that way instead. www.vzio.com
ASP WEB DEVELOPMENT



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top