Hi everyone,
I am some what new to JavaScript and I'm having a problem displaying my results from a function. The function is working, but the problem is that I have a form with a dropdown list that is a quantity field. What I would like it to do is when the user selects a number in the quantity field it would create a number of textboxes according to the number selected in the quantity field. Well, that seems to work, but the problem is when the quantity is selected the form disappears and only the textboxes show up at the top of the screen. I can't seem to place the textboxes where I want them to go. Is the code I have wrong? And why is it that the rest of the form disappears? I can really use some insight to this, I am totally confused.disappears? I can really use some insight to this, I am totally confused.
HTML Form
I am some what new to JavaScript and I'm having a problem displaying my results from a function. The function is working, but the problem is that I have a form with a dropdown list that is a quantity field. What I would like it to do is when the user selects a number in the quantity field it would create a number of textboxes according to the number selected in the quantity field. Well, that seems to work, but the problem is when the quantity is selected the form disappears and only the textboxes show up at the top of the screen. I can't seem to place the textboxes where I want them to go. Is the code I have wrong? And why is it that the rest of the form disappears? I can really use some insight to this, I am totally confused.disappears? I can really use some insight to this, I am totally confused.
Code:
<script language="javascript" type="text/javascript">
var qty = document.testform.element.qty.value;
function testfor(qty){
for (var i=0; i<qty; i++) {
document.write('<input type="text" name="' + i + '" size="20">' + ' ' + i + '<br>');
}
}
</script>
HTML Form
Code:
<form name="testform" method="POST">
<table border="1" width="100%">
<tr>
<td width="22%">
<select size="1" name="qty" onchange="testfor(this.value)">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</td>
<td width="77%">
<script language="javascript" type="text/javascript">
<!--
testfor();
//-->
</script>
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="Submit" name="B1">
<input type="reset" value="Reset" name="B2"></p>
</td>
</tr>
</table>
</form>