Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Sep 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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"/>

  • #2
    Senior Coder TheShaner's Avatar
    Join Date
    Sep 2005
    Location
    Orlando, FL
    Posts
    1,126
    Thanks
    2
    Thanked 40 Times in 40 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •