...

View Full Version : option value cost



bazzano
09-20-2005, 10:41 AM
Sorry guys disregard my previous post i sorted figured out a little bit of the problem but how would i select a product from a option value list then make its cost display in a text field. The cost of each product is unique how can i do that




<tr> <td align="left">Product Selection</td><td align="left">

<SELECT NAME="mylist" onchange="this.form.mycost.selectedIndex=this.selectedIndex;">
<OPTION VALUE="m1">Canora Stratocaster
<OPTION VALUE="m2">Fender Stratocaster
<OPTION VALUE="m3">Guild Electric
<OPTION VALUE="m4">Gibson Flying V
<OPTION VALUE="m5">Monterey
</SELECT><br></td></tr>
<tr> <td align="left">Cost</td> <td align="left">

<input type = "text" name = "mycost" id="mycost" size="20"/>

TheShaner
09-20-2005, 08:22 PM
There's a few ways you could do this:


<tr><td align="left">Product Selection</td><td align="left">

<SELECT NAME="mylist" onchange="updateCost(this.form)">
<OPTION VALUE="m1">Canora Stratocaster
<OPTION VALUE="m2">Fender Stratocaster
<OPTION VALUE="m3">Guild Electric
<OPTION VALUE="m4">Gibson Flying V
<OPTION VALUE="m5">Monterey
</SELECT><br></td></tr>
<tr> <td align="left">Cost</td> <td align="left">

<input type = "text" name = "mycost" id="mycost" size="20"/>
And here's the function to go along with the above:

<script language="javascript">
function updateCost(myform)
{

switch(myform.mylist.value)
{
// Use your own cost values of course
case 'm1': myform.mycost.value = "$200"; break
case 'm2': myform.mycost.value = "$300"; break
case 'm3': myform.mycost.value = "$250"; break
case 'm4': myform.mycost.value = "$400"; break
case 'm5': myform.mycost.value = "$500"; break
}

}
</script>

Or this method works too. However, you the name of the guitars won't be stored in the dropdown since instead it stores the price. So this method may not be preferable, which makes the above one more flexible.


<tr><td align="left">Product Selection</td><td align="left">

<SELECT NAME="mylist" onchange="javascript: document.form.mycost.value=this.value;">
<OPTION VALUE="$200">Canora Stratocaster
<OPTION VALUE="$300">Fender Stratocaster
<OPTION VALUE="$250">Guild Electric
<OPTION VALUE="$400">Gibson Flying V
<OPTION VALUE="$500">Monterey
</SELECT><br></td></tr>
<tr> <td align="left">Cost</td> <td align="left">

<input type = "text" name = "mycost" id="mycost" size="20"/>

-Shane



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum