I have a script that is written based on the name and I would like to change it based on the id. I've tried simply switching getElementsByName to getElementById plus changing name to id where appropriate without luck. IE tells me "object doesn't support this property or method" and FF tells me "getElementByID is not a function" when I do that.
How is the best way to approach rewriting this script for Id?
Code:function initFillDown() { var aObj = document.getElementsByTagName('input'); var i = aObj.length; while(i--) { if(aObj[i].type=='text') { aObj[i].onchange = function() {lastChoice(this.name);}; } else { aObj[i].onclick = function() {fillDown(this);}; } } }; function lastChoice(ref) { var needle = /grade(\d+)_(\d+)$/i; ref.match(needle); down[(RegExp.$2)] = RegExp.$1; } var down = []; function fillDown(obj) { // button column var aObj = document.getElementsByName('copy'); var len = aObj.length; for(var i=0; i<len; i++) { if(aObj[i]==obj) { var col = i; break; } } // fill var aObj = document.getElementsByTagName('input'); var len = aObj.length; var idx = down[col]; var lastName = 'grade'+idx+'_'+col; var val = document.getElementsByName(lastName)[0].value; for(var i=0, count=0; i<len; i++) { if(aObj[i].name==lastName) { aObj[i].value = val; lastName = 'grade'+(++idx)+'_'+col; } } }



Reply With Quote

Bookmarks