0

I want to load a dropdown with numbers 1 - 20 and I have a javascript code to perform this. But Not sure how this function has to be called in the dropdown list.

$(document).ready(function(){
quantitydropdown();
})

function quantitydropdown()
{
  // Get reference to drop down
  var ddl = document.getElementById('quantitydropdownid');

  for (var i = 1; i < 21; i++) {
    var theOption = document.createElement("option");
    theOption.text = i;
    theOption.value = i;
    // If it is the first option, make it be selected
    i === 1 ? theOption.selected = "selected" :  "";
    ddl.options[i] = theOption;
  }
}
#quantitydropdownid { width:200px; }

#quantitydropdownid option:empty
{
  display:none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<label for="quantitydropdown">Quantity</label>
<select id="quantitydropdownid" runat="server"></select>

So I am not sure how I should call this javascript function into the dropdown list. Need help!!

Chiller
  • 9,520
  • 2
  • 28
  • 38
Akansha
  • 199
  • 2
  • 11
  • Do you need to load number on page load? – Jainil Apr 20 '17 at 14:28
  • your code works fine you just needed to add jquery to your page – Chiller Apr 20 '17 at 14:29
  • @Jainil yes I need to load numbers on load and want to select one number from the list. Also I am trying to link this script with the asp dropdown list control – Akansha Apr 20 '17 at 14:43
  • @chiller you have edited the code but the dropdown is not working fine. The value is not getting selected – Akansha Apr 20 '17 at 14:43
  • @VDWWD No its not a duplicate question. I want to link the javascript function with the control. – Akansha Apr 20 '17 at 14:44
  • @Akansha its because you are calling the quantitydropdown function onchange, i edited the code, take a look. – Chiller Apr 20 '17 at 14:45
  • @chiller Thanks! that's working. But how do I link the function quantitydropdown() to the asp control quantitydropdownid ? Means, when I include this code under the script tag and the select control under body tag, I am not able to link the function. – Akansha Apr 20 '17 at 14:51
  • 1
    @Akansha you need to link the js file with the function in the asp page just like i linked jquery.js or you can add the js code inside a script tag inside the asp page – Chiller Apr 20 '17 at 14:57

0 Answers0