how to dynamically change form elements?

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

    how to dynamically change form elements?

    hi, all, thanks for reading.

    i have a form in which i want drop down boxes to dynamically change some
    hidden fields:


    <form name=test method="post" >

    Pearl Color:
    <select name="product1[]">
    <option value="Pearl: White" selected>White</option>
    <option value="Pearl: Lavendar">Laven dar</option>
    <option value="Pearl: Blue">Blue</option>
    </select>

    Crystal Color :
    <select name="product1[]">
    <option value="Crystal: White Opal" selected>White Opal</option>
    <option value="Crystal: Crystal AB">Crystal AB</option>
    <option value="Crystal: Black Diamond">Black Diamond</option>
    </select>

    Cap Choices:
    <select name="product1[]">
    <option value="Cap: Plain" selected>Plain</option>
    <option value="Cap: Fancy">Fancy</option>
    <option value="Cap: Regal">Regal</option>
    </select>

    <INPUT TYPE="HIDDEN" NAME="product2[]" VALUE="GET VALUES FROM ABOVE">
    <INPUT TYPE="HIDDEN" NAME="product3[]" VALUE="GET VALUES FROM ABOVE">

    <input name="submit" type="submit">
    </form>

    in the value of the hidden fields, i want a concatenation of the three
    select elements(the option value, not the text) above, like:
    Pearl: White Crystal: White Opal Cap: Fancy

    and it needs to post as if those selected options were hard coded into the
    hidden fields.

    ps, the <select name="product1[]"> cannot change

    thanks for your time, i'm all out of google<G>


    --

    juglesh B>{)}



  • Bruce Duncan

    #2
    Re: how to dynamically change form elements?

    "juglesh" <juglesh@nospam RadioKDUGspamsu x.com> wrote in message
    news:KpSoc.4362 4$iF6.4061654@a ttbi_s02...[color=blue]
    > hi, all, thanks for reading.
    >
    > i have a form in which i want drop down boxes to dynamically change some
    > hidden fields:
    > http://cynthialoganjewelry.com/test4.htm
    >
    > <form name=test method="post" >
    >
    > Pearl Color:
    > <select name="product1[]">
    > <option value="Pearl: White" selected>White</option>
    > <option value="Pearl: Lavendar">Laven dar</option>
    > <option value="Pearl: Blue">Blue</option>
    > </select>
    >
    > Crystal Color :
    > <select name="product1[]">
    > <option value="Crystal: White Opal" selected>White Opal</option>
    > <option value="Crystal: Crystal AB">Crystal AB</option>
    > <option value="Crystal: Black Diamond">Black Diamond</option>
    > </select>
    >
    > Cap Choices:
    > <select name="product1[]">
    > <option value="Cap: Plain" selected>Plain</option>
    > <option value="Cap: Fancy">Fancy</option>
    > <option value="Cap: Regal">Regal</option>
    > </select>
    >
    > <INPUT TYPE="HIDDEN" NAME="product2[]" VALUE="GET VALUES FROM ABOVE">
    > <INPUT TYPE="HIDDEN" NAME="product3[]" VALUE="GET VALUES FROM ABOVE">
    >
    > <input name="submit" type="submit">
    > </form>
    >
    > in the value of the hidden fields, i want a concatenation of the three
    > select elements(the option value, not the text) above, like:
    > Pearl: White Crystal: White Opal Cap: Fancy
    >
    > and it needs to post as if those selected options were hard coded into the
    > hidden fields.
    >
    > ps, the <select name="product1[]"> cannot change
    >
    > thanks for your time, i'm all out of google<G>
    >
    >
    > --
    >
    > juglesh B>{)}
    >
    >[/color]

    I think you are looking for something like the following:

    function updatefield()
    {
    lsel1 = document.forms["test"]["selPearl"].value
    lsel2 = document.forms["test"]["selCap"].value
    document.forms["test"]["product1"].value = lsel1 + lsel2
    }

    NOTE: I would name each element accordingly

    <form name=test method="post" >
    <select name="selPearl" onchange="updat efield();">
    <option value="Pearl: White" selected>White</option>
    <option value="Pearl: Lavendar">Laven dar</option>
    <option value="Pearl: Blue">Blue</option>
    </select>
    <select name="selCap" onchange="updat efield();">
    <option value="Cap: Plain" selected>Plain</option>
    <option value="Cap: Fancy">Fancy</option>
    <option value="Cap: Regal">Regal</option>
    </select>
    <INPUT TYPE="HIDDEN" NAME="product1" VALUE="">
    </form>

    I left out the third select...I'm sure you can get it from here.

    HTH
    -Bruce Duncan


    Comment

    • juglesh

      #3
      Re: how to dynamically change form elements?

      Bruce Duncan wrote:[color=blue]
      > "juglesh" <juglesh@nospam RadioKDUGspamsu x.com> wrote in message
      > news:KpSoc.4362 4$iF6.4061654@a ttbi_s02...[color=green]
      >> hi, all, thanks for reading.
      >>
      >> i have a form in which i want drop down boxes to dynamically change
      >> some hidden fields:
      >> http://cynthialoganjewelry.com/test4.htm[/color][/color]
      [color=blue][color=green]
      >>
      >> and it needs to post as if those selected options were hard coded
      >> into the hidden fields.
      >>
      >> ps, the <select name="product1[]"> cannot change[/color][/color]

      [color=blue]
      >
      > I think you are looking for something like the following:
      >
      > function updatefield()
      > {
      > lsel1 = document.forms["test"]["selPearl"].value
      > lsel2 = document.forms["test"]["selCap"].value
      > document.forms["test"]["product1"].value = lsel1 + lsel2
      > }
      >
      > NOTE: I would name each element accordingly[/color]

      well, thats the thing, the hidden element has to have the names i gave them
      to post to the cart properly. also, there are a few elements in the form
      with the same name="product1[]" , which completely broke it for some reason,
      i would think it would have changed the value in either just the first
      product1[]" it came to or to all of them.

      so, instead i used
      document.forms["choices"].elements[1].value = lsel1 + lsel2

      to insert the value into a hidden field in a completely different form from
      the color choices. set the variables with the first form, actually submit
      the second.

      thanks alot, a shove in the right direction is usually all i need!
      appreciate it.

      [color=blue]
      > <form name=test method="post" >
      > <select name="selPearl" onchange="updat efield();">
      > <option value="Pearl: White" selected>White</option>
      > <option value="Pearl: Lavendar">Laven dar</option>
      > <option value="Pearl: Blue">Blue</option>
      > </select>[/color]

      --

      juglesh B>{)}
      Music near and by Doug Cassidy Anacortes, WA 98221





      Comment

      Working...