Can someone help me to solve this problem
Javascript Code:
function CheckAll(pObj) {
var mCurrStatus;
mCurrStatus = pObj.checked;
var mObjList; mObjList = document.all["process"];
for (x = 0; x <= 2; x++) {
var Obj;
Obj = mObjList[x];
Obj.checked = mCurrStatus;
}
}
asp-classic code:
response.Write "<td nowrap><input type=checkbox name=process_1 "
response.Write "/>box1</td>"
response.Write "<td nowrap><input type=checkbox name=process_2 "
response.Write "/>box2</td>"
and this is my selectall box :
response.Write "<th align=left><input type=checkbox onclick=CheckAll(this)></th>"
how do i select thoses boxes when i click the select all box (it's seem the function doesn't work) please help me instead of giving me the example... thanks so much for you guy help~
Updated:
i refer to Roland suggestion and make the new function but doesn't work any idea?
function CheckAll() {
var eles = [];
var len = elems.length;
//var inputs = document.getElementsByTagName("input");
var elems = tab.getElementsByTagName("input");
for (var i = 0; i < len; i++) {
if (elems[i].name.indexOf('process_') == 0) {
eles.push(elems[i]);
}
}
//var elems = tab.getElementsByTagName("input");
for (var x = 0; x < len; x++) {
if (elems[x].type == "checkbox") {
elems[x].checked = true;
}
}
}
This is how you can select and check all the checkboxes:
First find your elements (this is vanilla.js):
// will find all the html elements that have a name containing the value passed
var find = function(name) {
// you can optimize this part a bit (pass the tag name)
var elements = document.getElementsByTagName("*");
var results = [];
for(var i = 0; i < elements.length; i++) {
var elementName = elements[i].name;
if(elementName !== undefined && elementName.indexOf(name) != -1) {
results.push(elements[i]);
}
}
return results;
};
Then this is how you use this "utility" function to check all:
var checkAll = function() {
var checkBoxes = find("process");
for(var i = 0; i < checkBoxes.length; i++) {
checkBoxes[i].checked = true;
}
}
Here is a fiddle:
As a side note, this bit here is not valid html (you're missing some quotes):
response.Write "<td nowrap><input type=checkbox name=process_1 "
response.Write "/>box1</td>"
I beleive it needs to be:
response.Write "<td nowrap><input type='checkbox' name='process_1' "
response.Write "/>box1</td>"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.