writing from hidden field to text field repost

Discussion in 'Javascript' started by Roy Adams, Dec 20, 2004.

  1. Roy Adams

    Roy Adams Guest

    Hi I'm reposting this question because for some reason can't post
    follow up question to this thread.
    What I'm trying to do is put the value and text from a a select in to
    a text field and to a hidden field respectfully and the value from
    dynamically created hidden fiields in to a text fieldin to a text
    field all at the same time
    Here's the code as viewed through the browser
    <body bgcolor="#FFFFFF" text="#000000" >

    <SCRIPT LANGUAGE=JavaScript>
    <!--
    function ch_price (theForm) {
    // this changes the price in the price text field
    for (i=0; i < 2; i++){
    document.form1.oldprice.value = document.form1.prevprice.value;//
    the hidden fields
    document.form1.price.value =
    document.form1.size.options[document.form1.size.selectedIndex].value;
    document.form1.Tsize.value =
    document.form1.size.options[document.form1.size.selectedIndex].text;

    }
    }
    //-->

    </SCRIPT>


    <form name="form1" method="post" action="" >
    <select name="size" id="size" onChange="ch_price(form1)">
    <option selected value="189.00">Select
    Size/Colour</option>


    <option value="179.00" >95x75cm; 37x29"</option>
    <option value=" 89.00" >95x75cm; 37x29"</option>


    </select>
    <br>
    <br>

    <input type="hidden" name="prevprice" value="99.00">//hidden fields
    that holds value for the oldprice txt field
    <input type="hidden" name="prevprice" value="189.00">

    <input name="oldprice" class="price" type="text" id="oldprice"
    readonly = true value="189.00" size="5" >
    <input name="price" class="price" type="text" id="price" readonly =
    true value="179.00" size="5" >
    <input type="hidden" name="Tsize" value="">
    </form>

    I've tried to simplify it by taking out any code
    T.I.A
     
    Roy Adams, Dec 20, 2004
    #1
    1. Advertising

  2. Roy Adams

    McKirahan Guest

    "Roy Adams" <> wrote in message
    news:...
    > Hi I'm reposting this question because for some reason can't post
    > follow up question to this thread.
    > What I'm trying to do is put the value and text from a a select in to
    > a text field and to a hidden field respectfully and the value from
    > dynamically created hidden fiields in to a text fieldin to a text
    > field all at the same time


    [snip]

    Your description and your logic conflict.

    Could you rewrite the above using your form field names?
     
    McKirahan, Dec 20, 2004
    #2
    1. Advertising

  3. Roy Adams

    Fred Oz Guest

    Roy Adams wrote:
    > Hi I'm reposting this question because for some reason can't post
    > follow up question to this thread.
    > What I'm trying to do is put the value and text from a a select in to
    > a text field and to a hidden field respectfully and the value from
    > dynamically created hidden fiields in to a text fieldin to a text
    > field all at the same time
    > Here's the code as viewed through the browser
    > <body bgcolor="#FFFFFF" text="#000000" >
    >
    > <SCRIPT LANGUAGE=JavaScript>


    The language attribute is dead and buried, use type:

    <script type="text/javascript">

    > <!--


    Hiding scripts hasn't been necessary since Netscape 2, don't bother.

    > function ch_price (theForm) {
    > // this changes the price in the price text field
    > for (i=0; i < 2; i++){
    > document.form1.oldprice.value = document.form1.prevprice.value;//
    > the hidden fields


    It is your job to make sure lines aren't inappropriately wrapped,
    always wrap at about 65 characters to allow for a couple of quoted
    replys

    [...]
    >
    > <form name="form1" method="post" action="" >
    > <select name="size" id="size" onChange="ch_price(form1)">
    > <option selected value="189.00">Select
    > Size/Colour</option>


    Get rid of tabs, use 2 (preferred) or 4 spaces for indenting.

    >
    > <option value="179.00" >95x75cm; 37x29"</option>
    > <option value=" 89.00" >95x75cm; 37x29"</option>


    Supposed to be selecting siz/color, how does this relate?

    > <input name="oldprice" class="price" type="text" id="oldprice"
    > readonly = true value="189.00" size="5" >


    Attribute values should be quoted, but readonly doesn't need one. You
    may want to put readonly="readonly", but that may fool some browsers
    that don't expect it to have a value.

    Also, somewhere you used // to comment in HTML - that won't work, you
    need to use <!-- -->

    [...]

    Below is an example of what you are trying to do. Post again if you
    need further help.


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
    <html><head><title>Copy Text & Values</title>

    <script type="text/javascript">

    function ch_price (sel,theForm) {

    // Get the options array
    var opts = sel.options;


    // for each option
    for (i=0; i < opts.length; i++) {

    // if it is selected
    if (opts.selected && i > 0) {

    // copy the value to the value inpput
    theForm.elements['valueField'].value = opts.value;

    // copy the text to the text inpput
    theForm.elements['hiddenField'].value = opts.text;

    } else if (i == 0) {
    theForm.elements['valueField'].value = '';
    theForm.elements['hiddenField'].value = '';
    }
    }
    }

    </script>
    </head>
    <body>

    <form name="form1" id="form1" method="post" action="" ><p>
    <select name="size" id="size" onChange="ch_price(this,this.form)">
    <option value="" selected>Select Size/Colour</option>
    <option value="value1" >Text one</option>
    <option value="value2" >Text Two</option>
    </select><br><br>

    <!-- hidden fields that holds value for the oldprice txt field -->
    <input type="text" name="valueField" value="" readonly>
    <input type="text" name="hiddenField" value="" readonly>
    </p></form>

    </body>
    </html>

    --
    Fred
     
    Fred Oz, Dec 21, 2004
    #3
  4. JRS: In article <41c7bee9$0$25868$5a62ac22@per-qv1-newsreader-
    01.iinet.net.au>, dated Tue, 21 Dec 2004 16:11:23, seen in
    news:comp.lang.javascript, Fred Oz <> posted :

    > It is your job to make sure lines aren't inappropriately wrapped,
    > always wrap at about 65 characters to allow for a couple of quoted
    > replys


    Recommendations vary in the range 64-76, but the accepted norm is 72.
    That allows sufficient room for reasonable quoting without reaching 80
    characters. An unnecessarily small figure, while perfectly OK for
    ordinary text, in restrictive for program material. You yourself appear
    to be using 72.

    --
    © John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME ©
    Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A.
    Web <URL:http://www.merlyn.demon.co.uk/news-use.htm> : about usage of News.
    No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
     
    Dr John Stockton, Dec 21, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mortar
    Replies:
    7
    Views:
    9,117
  2. Rick
    Replies:
    3
    Views:
    8,199
    Alexey Smirnov
    Apr 13, 2010
  3. GavMc
    Replies:
    4
    Views:
    342
    Evertjan.
    Sep 22, 2005
  4. Roy Adams

    writing from hidden field to text field

    Roy Adams, Dec 20, 2004, in forum: Javascript
    Replies:
    1
    Views:
    198
  5. SolarCanine
    Replies:
    2
    Views:
    291
    SolarCanine
    Sep 20, 2005
Loading...

Share This Page