Hi I have a problem with retrieving first populated, than selected by user quantity from the select dropdown menu.
I have several the same numeric type of menus. They contain values 0-20. 
Event onchange causes the selected number to be displayed in an html div. It works fine. However, if I try to get the selected number back from the div for my calculations, it doesn't work. 
I spent hours on it, any help greatly appreciated....

function showNumber(selectId, divNumber) {

  var select = document.getElementById(selectId);
  var noItems = document.getElementById(divNumber);

  for (var i = 0; i <= 20; i++) {

    var option = document.createElement('option');
    option.innerHTML = i;
    option.value = i;

    select.appendChild(option);
  }

  select.onchange = function () {
    var noZero = select.value;
    if (noZero > 0) {
      noItems.innerHTML = noZero;
    } else noItems.innerHTML = " ";
  };
}



  function showDivs(){
showNumber('item1', 'div1');
showNumber('item2', 'div2');
showNumber('item3', 'div3');
showNumber('item4', 'div4');
}

Recommended Answers

However, if I try to get the selected number back from the div for my calculations, it doesn't work.

I don't see where are you trying to get it.
ALso you can make some variable and store the copy of the value in the variable when setting to …

Jump to Post

All 2 Replies

However, if I try to get the selected number back from the div for my calculations, it doesn't work.

I don't see where are you trying to get it.
ALso you can make some variable and store the copy of the value in the variable when setting to div. So then you will be able to take from variable.

Do you mean like:

  function showDivs(){
var a = showNumber('item1', 'div1');
var b = showNumber('item2', 'div2');
showNumber('item3', 'div3');
showNumber('item4', 'div4');
}

I have tried that originally, but it doesn't seem to work. My thought was to add an array that would hold the values the onchange function populates and retrieve them from there, but I just get totally mixed up, I am a beginner and not realy sure if that's the right thing to do...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.