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
    Jun 2004
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Adding numbers linked to data

    My code so far is as follows:

    <html>
    <head>
    <script type="text/javascript">
    function put()
    {
    txt=document.forms[0].myList.options[document.forms[0].myList.selectedIndex].text
    document.forms[0].favorite.value=txt
    }
    </script>
    </head>

    <body>
    <form>
    Select your power supply:
    <select name="myList" onclick="put()">
    <option>450 watt power +$0.00</option>
    <option>550 watt power +$15.00</option>
    <option>650 watt power +$50.00</option>
    </select>
    <br /><br />
    Your selection is: <input type="text" name="favorite" size="20">
    </form>
    </body>

    </html>

    --------------------------
    I want to link numbers to each option then display the number linked to the option instead of the whole option. This script is working. And I hope to be able to add many options to get a final value. Thanks for any help available.

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    function put(objSel)
    {
    objSel.form.favorite.value=objSel.options[objSel.selectedIndex].value;
    }
    ...
    <select name="myList" onclick="put(this)">
    <option value="">Choose one</option>
    <option value="450">450 watt power +$0.00</option>
    <option value="550">550 watt power +$15.00</option>
    <option value="650">650 watt power +$50.00</option>
    </select>

    See how the function can be shortened and be made flexible by using function parameters.


  •  

    Posting Permissions

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