0

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 better if done on client side.

halfer
  • 19,824
  • 17
  • 99
  • 186
asma
  • 2,795
  • 13
  • 60
  • 87

3 Answers3

1

Use jQuery and this code:

var count = $('#dropDown').val();
for(i = 0; i < count; i++)
{
   $('#textboxContainer').append("<input type='text' />");
}
Saeed Neamati
  • 35,341
  • 41
  • 136
  • 188
  • This is a great solution, but you might need to consider postbacks, and rendering of these dynamic elements. Give them ids that you can iterate through to rebind, if required? – Oxonhammer Jul 14 '11 at 14:26
0
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.

hungryMind
  • 6,931
  • 4
  • 29
  • 45
0

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/

Alexander Beletsky
  • 19,453
  • 9
  • 63
  • 86