Hi I’m really new in Javascript…
I’m trying to build list of input text box when user selects option.
However, when user changes option, input text box is created beside previous input text box. Hence, there could be 100 input boxes if user continuously changes option.
I want my program to delete everything in span and generate list of input text boxes.
Please, give me any suggestions!
function myInputs() {
alert('writing inputs');
var value = document.getElementById("name").value;
var split = value.split(",");
var size = split.length;
var out = document.getElementById("inputBox");
$(this).parent('display').remove(); //doesn't delete any...
for (var j=0; j<size; j++){
if (split[j] != ""){
var element = document.createElement("input");
//Assign different attributes to the element.
element.setAttribute("type", "text");
element.setAttribute("value", split[j]);
element.setAttribute("name", split[j]);
out.appendChild(element);}
}
};
//html
<table border="0">
<tr>
<td>Select run : </td>
<td><select id="name" name="name" onchange="myInputs()">
<option value="time" name="timer">timer</option>
<option value="date,time" name="Performance">Performance</option>
<option value="location,time" name="Copy">Copy</option>
</select>
</td>
</tr>
</table>
<div id="display"><span id = "inputBox"></span></div>
Your selector doesn’t look right, try: