开发者

Registration Form Help

开发者 https://www.devze.com 2023-03-28 13:48 出处:网络
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

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>

http://jsfiddle.net/y9GRk/2/

0

精彩评论

暂无评论...
验证码 换一张
取 消