View Single Post
Old 10-05-2012, 09:28 AM   PM User | #1
taypandt
New Coder

 
Join Date: Aug 2012
Posts: 24
Thanks: 5
Thanked 0 Times in 0 Posts
taypandt is an unknown quantity at this point
Adding item from drop down list to an array

I'm trying to write a function that will take a selected item from a drop down list and add it to an array, which is then printed in a text field on the page, but I'm having trouble referencing the value.

Here's my function:
Code:
function addTool() {
        if (document.forms[0].toolList.value == "")
            window.alert("You must choose at least one item to purchase.");
        else {
            var dd1 = document.getElementById('toolList');
            var toolArray = new Array();
            var count = 0;
            toolArray.push(dd1.options[dd1.selectedIndex].text);
            document.forms[0].buyList.options[count].value = toolArray[count];
            count++;
            }
        }
And the code which tries to use it:
Code:
<select name="toolList">
        <option value="" style="display:none;"></option>
        <option value="cDrill">Cordless Drill</option>
        <option value="cScrew">Cordless Screwdriver</option>
        <option value="circSaw">Circular Saw</option>
        <option value="bandsaw">Bandsaw </option>
        <option value="discsander">Disc Sander</option>
        </select></p>
        <p><select name = "buyList" multiple = "multiple"
                        size = "10" style = "width: 500px">
                        <option value = "none">Items to be purchased</option>
                        </select></p>
        <p><input type = "button" value = "Add Tool"
                        onclick = "addTool();" style = "width: 120px" />
Right now I have no idea if I'm even close to having this correct. What would be the best way to do this?
taypandt is offline   Reply With Quote