PDA

View Full Version : HTML field auto-fill


Opel_Corsa
04-11-2007, 01:21 PM
There's a drop-down menu on my page that I would like to "link" to a text box (it's not a user-interactive field). Lets say the drop-down includes a list of products and the text box is to display the manufacturer. What I want to achieve is to have the text box display the corresponding manufacturer for each selected product, automatically. i.e. once the product is selected the box should be filled with the correct text value. Please note that there's no Submit button to do this; the box should auto-fill right away when the product is selected from the list.

The whole thing is part of a single form, and there's a lookup table that is used to find the appropriate mfg for the chosen product.

Any help is appreciated.

P.S> I'm thinking to achieve this in HTML and/or JScript but I'm not all that great with the latter.

P.SS> Something similar to this: http://www.htmlforums.com/client-side-scripting/t-client-side-dynamic-auto-complete-help-58880.html but my case deals with drop-down list.

ASMBlah
04-16-2007, 01:52 PM
Hi,

I think you mean the following


<script type="text/javascript">
var objLookupTable =
{
Default:"<No product selected>",
Prod1:"Manu1",
Prod2:"Manu2",
Prod3:"Manu3",
Prod4:"Manu4"
};

function funcGetManufacturer(objDropDown)
{
var objManufacturerTextBox = document.getElementById("txtManufacturer");
objManufacturerTextBox.value = objLookupTable[objDropDown.value];
}
</script>

<select onchange="funcGetManufacturer(this);">
<option value="Default"></option>
<option value="Prod1">Product 1</option>
<option value="Prod2">Product 2</option>
<option value="Prod3">Product 3</option>
<option value="Prod4">Product 4</option>
</select>

Manufacturer of selected product is
<input type="text" id="txtManufacturer" value="<No product selected>" disabled>


Hope this helps

Dan