Hi guys,
I'm a javascript beginner and I am trying to write this simple javascript code that will add text field when I type some texts in the preexisting text field. When the text field is onblur, javascript will see if the type of the text's value is either number or string.
Depending on its type it will create either a text field or a button. However, for some reason, nothing is happening. Could you check my code and see what's wrong with it? Thank you.
[HTML]
<div id="add" >
<form action="addform test2.html" method="post" name="addformte st" >
<input type="text" onblur="addform ()" name="copy" value="" />
<div id="inhere"> </div>
</form>
</div>
[/HTML]
I'm a javascript beginner and I am trying to write this simple javascript code that will add text field when I type some texts in the preexisting text field. When the text field is onblur, javascript will see if the type of the text's value is either number or string.
Depending on its type it will create either a text field or a button. However, for some reason, nothing is happening. Could you check my code and see what's wrong with it? Thank you.
Code:
<script type="text/javascript" >
var defaultname = "workout";
var defaultnumber = 0;
var forms2;
var text1;
var text1type;
function addform() {
defaultnumber++;
text1 = document.getElementsByName("copy");
text1type = typeof text1.value;
if (text1type == "number") {
forms2 = document.createElement("input");
forms2.type = "text";
forms2.name = defaultname + defaultnumber;
inHere = document.getElementById("inhere");
inHere.appendChild(forms2);
} elseif (text1type == "string") {
forms2 = document.createElement("input");
forms2.type = "button";
forms2.name = defaultname + defaultnumber;
forms2.value = "button";
inHere = document.getElementById("inhere");
inHere.appendChild(forms2);
} else document.write("wrong input");
}
</script>
[HTML]
<div id="add" >
<form action="addform test2.html" method="post" name="addformte st" >
<input type="text" onblur="addform ()" name="copy" value="" />
<div id="inhere"> </div>
</form>
</div>
[/HTML]
Comment