show value of textfield

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • printline
    New Member
    • Jul 2006
    • 89

    #1

    show value of textfield

    Hello All

    I have a script where i need to show the value of a text field in another textfield/field. I have done the same with my radio buttons and select fields like this:

    [HTML]<script type="text/javascript">
    function check(layers){
    document.forms[0].answer.value=l ayers
    }

    function PrintValues(){

    var myString = document.mainfo rm.file.value
    var myStringLength = myString.length
    var Comma = myString.lastIn dexOf(',')
    var SufNumChars = Comma + 1

    document.mainfo rm.result.value =('');

    for(i=0; i<Comma; i++)
    document.mainfo rm.result.value +=(myString.cha rAt(i));

    document.mainfo rm.result.value +=(' ');

    for(i=SufNumCha rs; i<myStringLengt h; i++)
    document.mainfo rm.result.value +=(myString.cha rAt(i));

    }

    </script>

    <div class="Accordio nPanelContent">
    <input name="layers" value="2" type="radio" onclick="check( this.value)" /> 2<br />
    <input name="layers" type="radio" onclick="check( this.value)" /> 4<br />
    <input name="layers" type="radio" onclick="check( this.value)" value="6" /> 6<br />
    <input name="layers" type="radio" onclick="check( this.value)" value="8" /> 8
    </div>
    <input type="text" name="answer" size="5" readonly="reado nly">
    <div class="Accordio nPanelContent">
    <select name="file" size="1" onchange="Print Values();" target="_parent ._top"
    onmouseclick="t his.focus()">
    <option value="DHL">Shi p with DHL</option>

    <option value="UPS">Shi p with UPS</option>
    </select>

    <input name="result">
    </div>
    [/HTML]
    But i can't seem to figure out how to do this with a textfield. Can anybody help me with this...???

    Best regards
    Last edited by acoder; Aug 5 '08, 10:43 AM. Reason: Added [code] tags
  • RamananKalirajan
    Contributor
    • Mar 2008
    • 608

    #2
    Hi Dude, I am sorry I am not able to follow your requirement clearly, but I had made some modification in ur code and it's working. Just check it out and post back if u need any change.

    [HTML]<html>
    <head>
    <script type="text/javascript">
    var resVal;
    function check(layer)
    {
    resVal=layer;
    // alert(resVal);
    }
    function printThis()
    {
    var result;
    result= resVal;
    result+=","+doc ument.getElemen tById('myAnswer ').value;
    var x = document.getEle mentById('myFil e').selectedInd ex;
    result+=","+doc ument.getElemen tById('myFile') .options[x].text;
    document.getEle mentById('myRes ult').value=res ult;
    }
    </script>
    </head><body>
    <form>
    <input type="radio" name="layers" onclick="check( this.value)"
    value="2">2<br />
    <input type="radio" name="layers" onclick="check( this.value)"
    value="4">4<br />
    <input type="radio" name="layers" onclick="check( this.value)"
    value="6">6<br />
    <input type="radio" name="layers" onclick="check( this.value)"
    value="8">8<br />
    <br />
    <input type="text" id="myAnswer">
    <br/>
    <select id="myFile">
    <option>Ship with DHL</option>
    <option>Ship with UPS</option>
    </select>
    <br/>
    <input type="text" id="myResult" onclick="printT his()">
    </form>
    </body>
    </html>[/HTML]

    Regards
    Ramanan Kalirajan

    Comment

    • printline
      New Member
      • Jul 2006
      • 89

      #3
      Works great, thanks, but what i really needed was a modification of the javascript, so that when i use a textfield in the form, the input of the textfield would also show in another textfield or <td> tag.

      Maybe be using getelementbyid or something like that, but can't quit figure out how to do that......

      Comment

      • RamananKalirajan
        Contributor
        • Mar 2008
        • 608

        #4
        Originally posted by printline
        Works great, thanks, but what i really needed was a modification of the javascript, so that when i use a textfield in the form, the input of the textfield would also show in another textfield or <td> tag.

        Maybe be using getelementbyid or something like that, but can't quit figure out how to do that......
        Hi dude, If u enter some characters in a textfield the same must be copied into another textfield. whether this is your requirement?

        Regards
        Ramanan Kalirajan

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          printline, as a full member now, you should know that we expect your code to be posted in [CODE] tags (See How to Ask a Question).

          This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

          Please use the tags in future. I don't want to have to tell you again.

          MODERATOR.

          Comment

          • printline
            New Member
            • Jul 2006
            • 89

            #6
            To RamananKaliraja n

            Yes, exactly what i need, but how do i do that....???

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              Try something like:
              [code=javascript]document.getEle mentById("IDofT extFieldToBeCop iedTo").value = document.getEle mentById("IDofT extFieldToBeCop iedFrom").value ;[/code]

              Comment

              • RamananKalirajan
                Contributor
                • Mar 2008
                • 608

                #8
                hi Dude, use this code.

                [HTML]<html>
                <head>
                <script language="javas cript">
                function printThis()
                {
                document.getEle mentById('myTex t2').value=docu ment.getElement ById('myText1') .value;
                }
                </script>
                </head>
                <body>
                Entered Text:<input type="text" id="myText1" onchange="print This()">
                <br/>
                Copied Text: <input type="text" id="myText2">
                </body>
                </html>[/HTML]

                Pls be careful of those white spaces while u copy the code.
                Any Probs post back it.

                Regards
                Ramanan Kalirajan
                Last edited by RamananKalirajan; Aug 6 '08, 04:26 AM. Reason: info: regarding the white spaces

                Comment

                • acoder
                  Recognized Expert MVP
                  • Nov 2006
                  • 16032

                  #9
                  Originally posted by RamananKaliraja n
                  [HTML]<script language="javas cript">[/HTML]
                  Don't use the language attribute. It's deprecated. Use the type attribute instead:[code=html]<script type="text/javascript">[/code]

                  Comment

                  • RamananKalirajan
                    Contributor
                    • Mar 2008
                    • 608

                    #10
                    Originally posted by acoder
                    Don't use the language attribute. It's deprecated. Use the type attribute instead:[code=html]<script type="text/javascript">[/code]
                    Ok Mr. Acoder here after I won't repeat the same mistake

                    Regards
                    Ramanan Kalirajan

                    Comment

                    • acoder
                      Recognized Expert MVP
                      • Nov 2006
                      • 16032

                      #11
                      No problem. Here's a link to the W3C documentation if you're interested.

                      Comment

                      • RamananKalirajan
                        Contributor
                        • Mar 2008
                        • 608

                        #12
                        Originally posted by acoder
                        No problem. Here's a link to the W3C documentation if you're interested.

                        hi Acoder, thank's for the link. It will be really helpful for me.

                        Regards
                        Ramanan Kalirajan

                        Comment

                        • printline
                          New Member
                          • Jul 2006
                          • 89

                          #13
                          Hello

                          All of your code works great, but i have run into a problem with my form. I have a field called total, where the value of the field is automatically generated from a script. I don't change this field manually.

                          Now i want to copy this field to another field by doing this:

                          Code:
                          <script language="text/javascript">
                          function printThis7()
                          {
                             document.getElementById('total2').value = document.getElementById('total').value; 
                          }
                          </script>
                          [HTML]<input type="text" onchange="print This7()" id="total" value="" name="total" size="10" readonly="reado nly">[/HTML]

                          and

                          [HTML]<input type="text" id="total2" value="" name="total2" size="10" readonly="reado nly">[/HTML]

                          but it doesn't copy the value...?

                          Is this because the value of the total field is automatically generated...? if so, how do i then copy the value...?

                          Comment

                          • RamananKalirajan
                            Contributor
                            • Mar 2008
                            • 608

                            #14
                            Originally posted by printline
                            Hello

                            All of your code works great, but i have run into a problem with my form. I have a field called total, where the value of the field is automatically generated from a script. I don't change this field manually.

                            Now i want to copy this field to another field by doing this:

                            Code:
                            <script language="text/javascript">
                            function printThis7()
                            {
                               document.getElementById('total2').value = document.getElementById('total').value; 
                            }
                            </script>
                            [HTML]<input type="text" onchange="print This7()" id="total" value="" name="total" size="10" readonly="reado nly">[/HTML]

                            and

                            [HTML]<input type="text" id="total2" value="" name="total2" size="10" readonly="reado nly">[/HTML]

                            but it doesn't copy the value...?

                            Is this because the value of the total field is automatically generated...? if so, how do i then copy the value...?
                            The reason why its not copied is on some of the browser onChange does't works properly. That's the reason. Don't worry about ur code its ok. Just change the onchange event to some other event like onBlur or onFocus

                            Regards
                            Ramanan Kalirajan

                            Comment

                            • nanaveraa
                              New Member
                              • May 2008
                              • 9

                              #15
                              [Reply=Nan Averaa]
                              Hello Frnd,
                              I'll small change your coding. Pls try again. All the best.
                              [Code=Nan]
                              <script type="text/javascript">
                              function check(layers){
                              document.forms[0].answer.value=l ayers
                              }

                              function PrintValues(){

                              var myString = document.mainfo rm.file.value
                              var myStringLength = myString.length
                              var Comma = myString.lastIn dexOf(',')
                              var SufNumChars = Comma + 1
                              alert(myString) ;//+"<br>"+myStrin gLength+"<br>"+ Comma+"<br>"+Su fNumChars);
                              document.mainfo rm.result.value =('');

                              for(i=0; i<Comma; i++)
                              document.mainfo rm.result.value +=(myString.cha rAt(i ));

                              document.mainfo rm.result.value +=(' ');

                              for(i=SufNumCha rs; i<myStringLengt h; i++)
                              document.mainfo rm.result.value +=(myString.cha rAt(i ));

                              }

                              </script>
                              <form name="mainform" >
                              <div class="Accordio nPanelContent">
                              <input name="layers" value="2" type="radio" onclick="check( this.value)" /> 2<br />
                              <input name="layers" type="radio" onclick="check( this.value)" /> 4<br />
                              <input name="layers" type="radio" onclick="check( this.value)" value="6" /> 6<br />
                              <input name="layers" type="radio" onclick="check( this.value)" value="8" /> 8
                              </div>
                              <input type="text" name="answer" size="5" readonly="reado nly">
                              <div class="Accordio nPanelContent">
                              <select name="file" size="1" onchange="Print Values();" target="_parent ._top"
                              onmouseclick="t his.focus()">
                              <option value="DHL">Shi p with DHL</option>

                              <option value="UPS">Shi p with UPS</option>
                              </select>

                              <input name="result">
                              </div>
                              </form>
                              [/Code]
                              [/Reply]


                              Originally posted by RamananKaliraja n
                              The reason why its not copied is on some of the browser onChange does't works properly. That's the reason. Don't worry about ur code its ok. Just change the onchange event to some other event like onBlur or onFocus

                              Regards
                              Ramanan Kalirajan

                              Comment

                              Working...