Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-20-2005, 10:41 AM   PM User | #1
bazzano
New to the CF scene

 
Join Date: Sep 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
bazzano is an unknown quantity at this point
option value cost

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


Code:
<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"/>
bazzano is offline   Reply With Quote
Old 09-20-2005, 08:22 PM   PM User | #2
TheShaner
Senior Coder

 
TheShaner's Avatar
 
Join Date: Sep 2005
Location: Orlando, FL
Posts: 1,125
Thanks: 2
Thanked 40 Times in 40 Posts
TheShaner will become famous soon enoughTheShaner will become famous soon enough
There's a few ways you could do this:

Code:
<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:
Code:
<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.

Code:
<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
TheShaner is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:52 AM.


Advertisement
Log in to turn off these ads.