Hi all,
I'm trying to set the onChange function of an input element on-the-fly.
Basically the html starts as, say:
onChange="flagthis('xxx');"
The 'xxx' is a hard-coded string.
I want to change it to:
onChange="flagthis('yyy');"
The Input element is part of td element in a cloned table row. After I do the appendChild to append this new row to the table, I use a For loop to loop through all td elements--each of which has an input element within.
What I'm doing thenis the following (semi-pseudocode):
I've debugged using an alert() and the variable tmpchg correctly replaces the 'xxx' with 'yyy'. But the setAttribute does *not* work. If I do an alert() showing the getAttribute of the onChange of that input immediately after the setAttribute--it still has the 'xxx' in it!
Can anyone tell me if something is wrong here?
--Thanks,
--Jim
I'm trying to set the onChange function of an input element on-the-fly.
Basically the html starts as, say:
onChange="flagthis('xxx');"
The 'xxx' is a hard-coded string.
I want to change it to:
onChange="flagthis('yyy');"
The Input element is part of td element in a cloned table row. After I do the appendChild to append this new row to the table, I use a For loop to loop through all td elements--each of which has an input element within.
What I'm doing thenis the following (semi-pseudocode):
Code:
//newrow was cloned from an existing row and each of it's
//..input's has onChange="flagthis('xxx');"
//The newrow has just been appended to the table.
//(the below line works fine, I've omitted some previous code)
var newrow = tnewrow.getElementsByTagName('td')
for(i=0;i<newrowtds.length;i++){
//below the childNode is the input element of the td
tmpx='' + newrow[i].childNodes[0].getAttribute('onChange')
tmpchg = tmpx.replace('xxx','yyy')
newrow[i].childNodes[0].setAttribute('onChange',tmpchg)
}
Can anyone tell me if something is wrong here?
--Thanks,
--Jim