javascript - Function didn't work with document.all -
can me solve problem
javascript code:
function checkall(pobj) { var mcurrstatus; mcurrstatus = pobj.checked; var mobjlist; mobjlist = document.all["process"]; (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 selectall box :
response.write "<th align=left><input type=checkbox onclick=checkall(this)></th>"
how select thoses boxes when click select box (it's seem function doesn't work) please me instead of giving me example... guy help~
updated:
i refer roland suggestion , make new function doesn't work idea?
function checkall() {
var eles = []; var len = elems.length; //var inputs = document.getelementsbytagname("input"); var elems = tab.getelementsbytagname("input"); (var = 0; < len; i++) { if (elems[i].name.indexof('process_') == 0) { eles.push(elems[i]); } } //var elems = tab.getelementsbytagname("input"); (var x = 0; x < len; x++) { if (elems[x].type == "checkbox") { elems[x].checked = true; } }
}
this how can select , check checkboxes:
first find elements (this vanilla.js):
// find html elements have name containing value passed var find = function(name) { // can optimize part bit (pass tag name) var elements = document.getelementsbytagname("*"); var results = []; for(var = 0; < elements.length; i++) { var elementname = elements[i].name; if(elementname !== undefined && elementname.indexof(name) != -1) { results.push(elements[i]); } } return results; };
then how use "utility" function check all:
var checkall = function() { var checkboxes = find("process"); for(var = 0; < checkboxes.length; i++) { checkboxes[i].checked = true; } }
here fiddle:
as side note, bit here not valid html (you're missing quotes):
response.write "<td nowrap><input type=checkbox name=process_1 " response.write "/>box1</td>"
i beleive needs be:
response.write "<td nowrap><input type='checkbox' name='process_1' " response.write "/>box1</td>"
Comments
Post a Comment