listbox selection to autopopulate fields?

Discussion in 'Javascript' started by Dave, Jan 25, 2005.

  1. Dave

    Dave Guest

    Hi folks,

    I'm in the middle of adding some validation functionality to an inventory
    tracking form.

    What I would like to do is have one dropdown menu/Listbox(Part Number) and
    another text field (Product Description).

    When the user selects an item from the drop down (IE 12S0FB) it will
    autopopulate the text field with a description of the product. At the
    moment I will hard code the values in. Can anyone help me out here?

    Thanks,
    Dave
     
    Dave, Jan 25, 2005
    #1
    1. Advertisements

  2. Let's say you've created an array of description strings named descs, your
    form is called form1 and it contains a textarea named descText.

    <select onchange="document.form1.descText.value=descs[this.selectedIndex]">
     
    Stephen Chalmers, Jan 25, 2005
    #2
    1. Advertisements

  3. Dave

    RobB Guest

    Use an object (not an array) to map part numbers to descriptions:

    var p_desc = {
    'IE 12S0FB' : 'Giant Veeblefetzer' ,
    'IE 76S0GB' : 'Tiny Veeblefetzer' ,
    .........
    'IE 22340x' : 'Blue Klarn'
    }

    Then...

    <select...onchange="product_description.value=(p_desc[this.options[this.selectedIndex].value]||'')">
    <option value="">choose</option>
    <option value="IE 12S0FB">IE 12S0FB</option>
    .........
    </select>
    <textarea name="product_description"></textarea>
     
    RobB, Jan 25, 2005
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.