开发者

Creating text boxes on client side on runtime

I have a drop down list and it has values through 2 to 12. Two text boxes are being displayed. What I want is when user change the dropdown's value, text boxes should be generated according to the count.

Should I do this on server side? I think it would be more be开发者_开发知识库tter if done on client side.


Use jQuery and this code:

var count = $('#dropDown').val();
for(i = 0; i < count; i++)
{
   $('#textboxContainer').append("<input type='text' />");
}


for(i=0;i<selectedValue;i++){
   var txt = document.createElement("input");
   txt.type = 'text';
   txt.id = "textbox_'+ i;
   document.getElementById('divId').append(txt);
}

If you want using JS.

Similar implementation you can do on asp.net, if you want from server side.


No, this have to be done client side with javascript. jQuery simplyfies that really much.

Here is the code that does what you need:

http://jsfiddle.net/mwSGB/2/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜