I’m trying to add an input element to [b]all
The script first searches for input elements with the name of “myinput”.
If it finds an input element with that name, it assigns the value “myvalue”.
If it can’t find an input element with that name, it tries to create a new one for all forms.
[code]
if (document.getElementsByName(‘myinput’)) {
var testcode = document.getElementsByName(‘myinput’);
for (var i=0; i < testcode.length; i++){
testcode[i].value = “myvalue”;}
}
else {
var z = document.createElement(“input”);
z.type = “hidden”;
z.name = “myinput”;
z.value = “myvalue”;
z.id = “mycode”;
var d = document.getElementsByTagName(‘form’);
for (var i=0; i < d.length; i++){
d.appendChild(z);}
}
What’s wrong with my code?
Thanks!