Hi there
I'm adding form fields on the fly with some javascript DOM programming.
I basically just clone a hidden <div>, then adjust node properties to
make this new <div> have unique values (style, size, etc.)
the original code of the input tag is:
<input type="file" onchange="alert('original')" size="30" id="filea"
name="filea">
One thing I'd like to do is to the onChange event value. I use the
following code to assign my new 'file' input field a new id and name:
newField[i].id=nameFile+newNum;
newField[i].name=nameFile+newNum;
Basically, this changes my form field id and name from 'filea' to
'filea1'. Works fine. I'd like to alter the 'onchange' value in this
same block of code.
Using the Firefox DOM Inspector, I can see that my file input field has
the following properties: type,style,size,name,id,onchange. I can easily
change this field's size to 5 (originally it was 35) by adding:
newField[i].size = '5'
and I can see that it works - my new file input field is 5 characters. If
I look at the field in the DOM Inspector, indeed I see that the nodeValue
of the nodeName "size" is 5.
apparantly I am wrong in assuming that I could change the field's
onChange value in a similar way! doing the following does nothing - it
doesn't change the "onchange" node value (or the alert message) at all.
newField[i].onchange = 'alert(\'changed\')';
to repeat, looking at my DOM Inspector after this script runs, the
nodeValue of the nodeName "onchange" has not changed, even though the
"size" node does change with similar syntax.
I get an interesting value of the onChange element via:
alert(newField[i].onchange). It gives me:
function onchange(event) {
alert("original");
}
Very interesting... not what I was expecting.
How can I dynamically change the 'onchange' value of the file input
field?
Hope I haven't lost anyone!! Much thanks.