View Single Post
Old 01-10-2013, 09:01 PM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,217
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
This is clearly very wrong:
Code:
    addOption.innerHTML = [i];
    addOption.value = [i];
options do not *HAVE* any innerHTML property.

In addition, you are setting the value to an *ARRAY*!!! [i] is an array of one element. Why?

Let's just throw out your code, okay? And do it the simple simple way.

Code:
function setOptionsForDropdown()
{ 
   for ( prodnum = 1; prodnum <= 10; ++prodnum )
   {
        var select = document.getElementById("product" + prodnum );
        for(var i = 0; i <=20; i++) 
        {
            select.options[i] = new Option( i, i );
        }
    }
}
I would also like to see your getInput function.

If indeed "divQuant" is the ID of some <div>, then why would you name the function getInput instead of getOutput or getDiv. Or, for that matter, why even *have* that function???

Why not simply:
Code:
<select id="product1"
        onchange="document.getElementById('divQuant').innerHTML=this.value;">
or equivalent?

That is, you could do it all in the same function:
Code:
function setOptionsForDropdown()
{ 
   for ( prodnum = 1; prodnum <= 10; ++prodnum )
   {
        var select = document.getElementById("product" + prodnum );
        for(var i = 0; i <=20; i++) 
        {
            select.options[i] = new Option( i, i );
        }
        select.onchange = 
            function( ) 
            {
                document.getElementById('divQuant').innerHTML=this.value;
            };      

    }
}
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote