At all I am trying to create a reg开发者_开发问答istration form that has the following purpose that if I select a number from the drop down list then it should dynamically generate that much number of certain text fields. For eg - if a parent tries to register his children in an application then he selects the number of children from a drop down list and then the form generator dynamically generates the required number of fields corresponding to the number of children.
<select id="foo">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<div id="bar">
</div>
<script>
//foo is the dropdown's id
$("#foo").change(function(){
var no = parseInt(this.value);
//remove all existing textboxes
$("#bar input").remove();
for(var i = 0; i< no ;i++)
$("<input/>",{
type:"text",
id:"baz"+i
}).appendTo("#bar");
//bar is where you want to append the textbox
});
</script>
精彩评论