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
    Oct 2002
    Location
    New Mexico
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Setting a value dynamically from Selection

    Hi to anyone out there who may have some knowledge about setting values from the result of a select in a selection list. I've written some test code in which the object is to set the value of a product description in an MGI (Modular Gateway Interface) tag with the result of a selected item in a selection list box. I've tried several things but none seem to yield the text value of the selection. Below is the test code:
    <head>
    <title>JS Test Page</title>
    <!------- Begin JavaScript ----->
    <script language="JavaScript">
    function setVar() {
    tvar = TSB.TSB.ProductSelection.optionSelected.text;
    }

    </script>
    <!------- End JavaScript ----->
    </head>
    <mgitoken>
    <body>
    <form name="TSB" action="shoppingbasket.html" method="post">
    <table border="1" width="100%">
    <tr><!-- Row 1 -->
    <td width="50%" align="center">
    <p><mgiBuyMe productID="101003"
    briefdescription="tvar"
    price="19.95"
    shippingCost="6.95"
    quantitySize="3"><font face="Arial, Helvetica, sans-serif"><b>101003</b> Utensil
    Holder 3&quot; x 7&quot; Ea. <b>$19.95</b></font></p></td><!-- Col 1 -->
    <td width="50%" align="center">
    <select name="ProductSelection" onChange="setvar()">
    <option value="Prod1">Product 1</option>
    <option value="Prod2">Product 2</option>
    <option selected value="Prod3">Product 3</option>
    </select>

    </td><!-- Col 2 -->
    </tr>
    <tr><!-- Row 2 -->
    <td colspan="2" valign="bottom" align="center">
    <input src="buyme.jpg" type="image" height="30" border="0">&nbsp; <input type="reset">&nbsp;&nbsp;<input type="text" value=tvar ></td><!-- Col 1 -->
    </tr>
    </table>
    </form>
    </body>
    </mgitoken>

    It would be very helpful if somone could refer some example code.
    I'm sure that I can't be the only one to ever want to try this.
    Thanks in advance to anyone that responds. I'm sure your time is valuable and it is appreciated that you've taken the time to respond and help.


    Jean-Raul @ziapublishing

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,965
    Thanks
    0
    Thanked 236 Times in 233 Posts
    this is not a DOM question. you should have post at the javascript forum

    anyway, you should do it like this:

    function setVar() {
    tvar = document.TSB.ProductSelection.options[document.TSB.ProductSelection.selectedIndex].text;
    }


    but you can simplify it like this:

    function setVar(objSelect) {
    tvar = objSelect.options[objSelect.selectedIndex].text;
    }

    then in the html:

    <select name="ProductSelection" onChange="setvar(this)">


  •  

    Posting Permissions

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