javascript - Retrieve child nodes of specific schema type from input control -
i have legacy document additional schema based tags in it:
<td class="inputcontrol"> <input id="offsetaccountsrequired_r0" type="radio" name="offsetaccountsrequired_n" value="y" >yes <tla:instruction type="unhide" value="offsetaccountsapp1"></tla:instruction> <tla:instruction type="jscript" value="//irrelevant javascript here"></tla:instruction> </input> <input id="offsetaccountsrequired_r1" type="radio" name="offsetaccountsrequired_n" value="n">no <tla:instruction type="hide" value="offsetaccountsapp1~offsetaccountsappls1and2"></tla:instruction> </input> <input id="offsetaccountsrequired_r2" type="radio" name="offsetaccountsrequired_n" value="" checked="true" class="hiddenradio" onclick="validate_js(this)"> <tla:instruction type="hide" value="offsetaccountsapp1~offsetaccountsappls1and2"></tla:instruction> </input> </td>
and dreadful javascript called validate_js(this) event works on tags:
// calling line - in case 'obj' input control 'offsetaccountsrequired_r2' tlainstructions = getinstructiontags(obj, 'tla:instruction'); function getinstructiontags(inputid,tagtype){ var coltla; var coltlaarray = new array(); tagtype = tagtype.touppercase(); var tlafinished = false; coltla = inputid.parentnode.childnodes; for(var i=0;i<coltla.length;i++){ if(coltla[i].nodename.touppercase() == 'input' && coltla[i].id == inputid.id){ for(var j=i;j<coltla.length;j++){ if(coltla[j].nodename.touppercase() == tagtype){ coltlaarray[coltlaarray.length] = coltla[j]; } if(coltla[j].nodename.touppercase() == '/input'){ tlafinished = true; break; } } } if(tlafinished){ break; } } return coltlaarray; } }
my task bring javascript spec work in ie9 (it ever used in vb6 web browser control).
as far can tell limited javascript skills code meant retrieve tla:instruction nodes within input element. using line coltla = inputid.parentnode.childnodes
which looks odd it's going level , down level. assume because retrieving tla:instruction elements doesn't retrieve nodes if use coltla = inputid.getelementsbytagname('tla:instruction')
.
is there simpler way retrieve array of elements of specific type within input control?
according html spec input
tags cannot have content.
start tag: required, end tag: forbidden
so, attached parent of input element hence reason why inputid.parentnode.childnodes
here simplified version using nextsibling
function getinstructiontags(inputid,tagtype){ var coltla; var coltlaarray = []; tagtype = tagtype.touppercase(); var tlafinished = false; var next = inputid; while ( !tlafinished ) { var next = next.nextsibling; tlafinished = next == null; if ( !tlafinished ) { var nodename = next.nodename.touppercase(); if ( nodename == tagtype ) { coltlaarray.push(next); } else { tlafinished = (nodename != '#text'); } } } return coltlaarray; }
Comments
Post a Comment