listbox selection to autopopulate fields?

D

Dave

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
 
S

Stephen Chalmers

Dave said:
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

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]">
 
R

RobB

Dave said:
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

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>
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top