automatic form element tab

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • yacobson

    automatic form element tab

    Hello
    Need help setting this up so that the value selected in the "Ship"-select
    box, will appear in the "Price"-text box automatically. (before submitting
    the form or clicking on the price box).
    <td><select name="Ship">
    <option value="" >Select</option>
    <option value="500">A</option>
    <option value="400">B</option>
    <option value="300">C</option>
    <option value="200">E</option>
    <option value="600">D</option>
    </select>
    </td>
    <td>$&nbsp;<inp ut type="text" name="Price" value="" size="4"></td>


    Thanks
    SY


  • McKirahan

    #2
    Re: automatic form element tab

    "yacobson" <yacobson@earth link.net> wrote in message
    news:s3vcd.7928 $SZ5.1396@newsr ead2.news.atl.e arthlink.net...[color=blue]
    > Hello
    > Need help setting this up so that the value selected in the "Ship"-select
    > box, will appear in the "Price"-text box automatically. (before submitting
    > the form or clicking on the price box).
    > <td><select name="Ship">
    > <option value="" >Select</option>
    > <option value="500">A</option>
    > <option value="400">B</option>
    > <option value="300">C</option>
    > <option value="200">E</option>
    > <option value="600">D</option>
    > </select>
    > </td>
    > <td>$&nbsp;<inp ut type="text" name="Price" value="" size="4"></td>
    >
    >
    > Thanks
    > SY[/color]

    Will this help? Watch for word-wrap.

    <html>
    <head>
    <title>shiprice .htm</title>
    <script type="text/javascript">
    function ship(that) {
    var form = document.forms[0];
    var valu = form.Ship.optio ns[form.Ship.selec tedIndex].value;
    form.Price.valu e = valu;
    }
    </script>
    </head>
    <body>
    <form>
    <table border="0">
    <tr>
    <td>
    <select name="Ship" onchange="ship( )">
    <option value="">Select </option>
    <option value="500">A</option>
    <option value="400">B</option>
    <option value="300">C</option>
    <option value="200">E</option>
    <option value="600">D</option>
    </select>
    </td>
    <td>
    $&nbsp;<input type="text" name="Price" value="" size="4">
    </td>
    </tr>
    </table>
    </form>
    </body>
    </html>


    Comment

    • Michael Winter

      #3
      Re: automatic form element tab

      On Sun, 17 Oct 2004 14:10:32 GMT, yacobson <yacobson@earth link.net> wrote:
      [color=blue]
      > Need help setting this up so that the value selected in the
      > "Ship"-select box, will appear in the "Price"-text box automatically.
      > (before submitting the form or clicking on the price box).[/color]

      The, "before submitting the form", part worries me a little. Make sure you
      don't depend on this action happening. It might not.

      [snip]

      Mike

      --
      Michael Winter
      Replace ".invalid" with ".uk" to reply by e-mail.

      Comment

      • Michael Winter

        #4
        Re: automatic form element tab

        On Sun, 17 Oct 2004 16:03:54 GMT, McKirahan <News@McKirahan .com> wrote:

        [snip]
        [color=blue]
        > function ship(that) {[/color]

        You add an argument, but you don't pass anything, nor do you use that
        argument. That strikes me as a little odd. Did you forget about it?
        [color=blue]
        > var form = document.forms[0];
        > var valu = form.Ship.optio ns[form.Ship.selec tedIndex].value;
        > form.Price.valu e = valu;[/color]

        Assuming you passed the argument, you could use:

        var elem = that.form.eleme nts;
        elem['Price'].value = that.value;

        If you want to use the options collection (though there shouldn't be any
        need), change the last line to:

        elem['Price'].value = that.options[that.selectedIn dex].value;
        [color=blue]
        > }[/color]

        [snip]
        [color=blue]
        > <select name="Ship" onchange="ship( )">[/color]

        The script changes above obviously require a change here:

        <script name="Ship" onchange="ship( this);">

        [snip]

        Mike

        --
        Michael Winter
        Replace ".invalid" with ".uk" to reply by e-mail.

        Comment

        Working...