Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Javascript help - Using Array to auto fill form

Avatar of shwekhaw
shwekhaw asked on
13 Comments1 Solution740 ViewsLast Modified:
Let's say I am selling shirts and pants. There are multiple products. For each product, I have a dropdown select box containing different color options and textfield next to it which is to show the price associated for each color. I want the price shown in the text field changes as user chooses different color. I have array created under javascript in this format:
Array[]= Array (price,color_code,product)
color_code are W,B,Y,G etc  (W for white, B for black etc)

Currently I have following array created
<SCRIPT type="text/javascript" language="JavaScript 1.2">
var Xarray = new Array();
Xarray [0] = new Array('15, 'B', 'Shirt');
Xarray [1] = new Array('16, 'W', 'Shirt');
Xarray [2] = new Array('18, 'Y', 'Shirt');
Xarray [3] = new Array('12, 'G', 'Shirt');
Xarray [4] = new Array('11, 'B', 'Pant');
Xarray [5] = new Array('13, 'W', 'Pant');
Xarray [6] = new Array('12, 'Y', 'Pant');
Xarray [7] = new Array('18, 'G', 'Pant');

And I have select box and textfield as follows.
<select name="product_type_color">
          <option value="W" selected>White</option>
          <option value="B">Black</option>
          <option value="Y">Yellow</option>
<input type="text" name="poduct_id_price">

Could someone help me write a javascript that will autofill the price textfield as change in dropdown select is triggered? Both type of product (shirt or pant) and Color (W,B,G,  or Y) must match to get a correct price.
Avatar of HonorGod
HonorGodFlag of United States of America imageSoftware Engineer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

This problem has been solved!
Unlock 1 Answer and 13 Comments.
See Answers