Click here to Skip to main content
15,884,628 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Below is my dropdown i need to add options to the first dropdown from 1 to 30 and I need to add options to the drop down 1 to 100 dynamically how can I do this?

<script type="text/javascript">
       function GetDynamicTextBox(value) {
           if (value == "") {
               return '<input name = "DynamicTextBox" type="text" value = "' + value + '" />  <Select id="ddlID" name = "DynamicTextDropdown"></Select>  <Select name = "DynamicTextDropdown"></Select>' +
                ' <input id="btnAdd123" type="button" value="Add" onclick="AddTextBox()" /><input type="button" value="Remove" onclick = "RemoveTextBox(this)" />'
           }

       }
       debugger;
       function GetDynamicTextBox1(value, i) {
           debugger;
           return '<input name = "DynamicTextBox" type="text" value = "' + value + '" />  <input name = "DynamicTextDropdown" id="ddlID" type="value" value = "' + i + '" />' +
                      ' <input id="btnAdd123" type="button" value="Add" onclick="AddTextBox()" /><input type="button" value="Remove" onclick = "RemoveTextBox(this)" />'
       }
       function AddTextBox() {
           var div = document.createElement('DIV');
           div.innerHTML = GetDynamicTextBox("");
           document.getElementById("TextBoxContainer").appendChild(div);
       }
       function AddTextBox1() {
           var inputCount = document.getElementById('TextBoxContainer').getElementsByTagName('input').length;
           if (inputCount == "0") {
               var div = document.createElement('DIV');
               div.innerHTML = GetDynamicTextBox("");
               document.getElementById("TextBoxContainer").appendChild(div);
           }

       }
       function RemoveTextBox(div) {
           document.getElementById("TextBoxContainer").removeChild(div.parentNode);
       }

       function RecreateDynamicTextboxes() {
           var values = eval('<%=Values%>');
           if (values != null) {
               var html = "";
               for (var i = 0; i < values.length; i += 2) {
                   html += "<div>" + GetDynamicTextBox1(values[i], values[i + 1]) + "</div>";
               }
               document.getElementById("TextBoxContainer").innerHTML = html;
           }
       }
       window.onload = RecreateDynamicTextboxes;
   </script>
    <script type="text/javascript">


        $(document).ready(function () {
            debugger;
            var selectHTML = "";
            for (i = 1; i < 101; i++) {
                selectHTML += "<option value='" + i + "'>" + i + "</option>";
            }


            $("#ddlID").empty();
            $("#ddlID").append(selectHTML);
        });
   </script>


What I have tried:

i could not find the source for doing this
Posted
Updated 1-May-17 20:11pm
v4

1 solution

I think you have not searched in google for same, There is a thousands of solutions which will fulfill your need.

Anyway do this


HTML
<select id="ddlID"></select> 



JAVASCRIPT
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
   <script type="text/javascript">


       $(document).ready(function () {

       var selectHTML = "";
       for (i = 1; i < 101; i++) {
           selectHTML += "<option value='" + i + "'>" + i + "</option>";
       }


       $("#ddlID").empty();
       $("#ddlID").append(selectHTML);
   });
   </script>
 
Share this answer
 
v4
Comments
Member 12324523 2-May-17 1:43am    
it can be added in code behind in thousands of ways but i am not getting the id of my drop down in code behind
Nirav Prabtani 2-May-17 1:46am    
See my updated solution
Member 12324523 2-May-17 1:49am    
i had done the same but i am not getting 1 to 100 into my dropdown can you help me out as i am new to this
Nirav Prabtani 2-May-17 1:54am    
this will work for sure, please check updated answer
Member 12324523 2-May-17 1:59am    
i had done in this way by placing yor code but its not working

function GetDynamicTextBox(value) {
if (value == "") {
return '    ' +
' '
}

}
debugger;
function GetDynamicTextBox1(value, i) {
debugger;
return '  ' +
' '
}


$(document).ready(function () {

var selectHTML = "";
for (i = 1; i &lt; 101; i++) {
selectHTML += "<option value='" + i + "'>" + i + "</option>";
}


$("#ddlID").empty();
$("#ddlID").append(selectHTML);
});

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900