Jquery copy form inputs with keyupIs there an “exists” function for jQuery?Add table row in jQueryHow do I check if an element is hidden in jQuery?Setting “checked” for a checkbox with jQuery?How to check whether a checkbox is checked in jQuery?Convert form data to JavaScript object with jQueryDisable/enable an input with jQuery?How can I refresh a page with jQuery?jQuery scroll to element“Thinking in AngularJS” if I have a jQuery background?

Was Constantine The Great a Nicene Christian?

Horizontal alignment of matrix in an array by using llap and phantom

Issues with the new Sitecore Support portal

Threatening to discontinue a service for a client

Does Estonia have discount supermarket chains like Aldi and Lidl?

How to pass Collection of exceptions as a root cause?

Please help me cook :(

Help me pair my socks

Why are Trump's handwritten notes being focused on in the news?

Why is it ethical for Ambassador Sondland to have been given an ambassadorship for campaign contributions?

Why does the Eurofighter Typhoon pitch up on brake release?

Miniseries in post-rapture US with good/evil conflict

What are the units of the product of two signals?

How to save custom label as parameter for a custom entity_reference field widget?

Is Fox News not classified as a news channel?

How can the mechanism of electrons in an atom be explained?

Did any of the Space Shuttles land through rain or rainclouds?

Why does E7 sharp 9 have a G?

How can I speed up secure erasing of a disk?

Do one quarter of Swedes named 'Ali' have a criminal record?

Pointlessly recurse down the alphabet

Why would a berry have a slow-acting poison?

Why I am not getting True when testing equation?

What is the largest piece of space debris volumetrically?



Jquery copy form inputs with keyup


Is there an “exists” function for jQuery?Add table row in jQueryHow do I check if an element is hidden in jQuery?Setting “checked” for a checkbox with jQuery?How to check whether a checkbox is checked in jQuery?Convert form data to JavaScript object with jQueryDisable/enable an input with jQuery?How can I refresh a page with jQuery?jQuery scroll to element“Thinking in AngularJS” if I have a jQuery background?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;









0


















Solved Needed to use the val instead of text. My mistake!



What is the difference when copying a form field to another form field vs copying a form field to a span id?



I can copy from input field to a span id no problem, but using the same method to copy from form field to another form field doesnt work.



Using Jquery keyup



Can anyone enlighten me?



Heres a Demo



Thanks in advance



 <input type="text" name="Quantity" value="100" id="quantity2" />
<input type="text" name="Quantity" id="quantity_img2" />

$("#quantity2").keyup(function ()
var value = $(this).val();
$("#quantity_img2").text(value);
).keyup();









share|improve this question

































    0


















    Solved Needed to use the val instead of text. My mistake!



    What is the difference when copying a form field to another form field vs copying a form field to a span id?



    I can copy from input field to a span id no problem, but using the same method to copy from form field to another form field doesnt work.



    Using Jquery keyup



    Can anyone enlighten me?



    Heres a Demo



    Thanks in advance



     <input type="text" name="Quantity" value="100" id="quantity2" />
    <input type="text" name="Quantity" id="quantity_img2" />

    $("#quantity2").keyup(function ()
    var value = $(this).val();
    $("#quantity_img2").text(value);
    ).keyup();









    share|improve this question





























      0













      0









      0


      3






      Solved Needed to use the val instead of text. My mistake!



      What is the difference when copying a form field to another form field vs copying a form field to a span id?



      I can copy from input field to a span id no problem, but using the same method to copy from form field to another form field doesnt work.



      Using Jquery keyup



      Can anyone enlighten me?



      Heres a Demo



      Thanks in advance



       <input type="text" name="Quantity" value="100" id="quantity2" />
      <input type="text" name="Quantity" id="quantity_img2" />

      $("#quantity2").keyup(function ()
      var value = $(this).val();
      $("#quantity_img2").text(value);
      ).keyup();









      share|improve this question
















      Solved Needed to use the val instead of text. My mistake!



      What is the difference when copying a form field to another form field vs copying a form field to a span id?



      I can copy from input field to a span id no problem, but using the same method to copy from form field to another form field doesnt work.



      Using Jquery keyup



      Can anyone enlighten me?



      Heres a Demo



      Thanks in advance



       <input type="text" name="Quantity" value="100" id="quantity2" />
      <input type="text" name="Quantity" id="quantity_img2" />

      $("#quantity2").keyup(function ()
      var value = $(this).val();
      $("#quantity_img2").text(value);
      ).keyup();






      jquery forms






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jun 4 '12 at 16:35







      cantaffordretail

















      asked Jun 4 '12 at 16:30









      cantaffordretailcantaffordretail

      1,2763 gold badges22 silver badges42 bronze badges




      1,2763 gold badges22 silver badges42 bronze badges

























          4 Answers
          4






          active

          oldest

          votes


















          4



















          To set the value of textbox element use val() method instead of text().



          Working demo http://jsfiddle.net/LnDYA/20/






          share|improve this answer


























          • Thanks this is this answer

            – cantaffordretail
            Jun 4 '12 at 16:33


















          2



















          $("#quantity_img2").text(value);


          should be



          $("#quantity_img2").val(value);


          DEMO



          Why this happen



          Because #quantity_img2 is an input field , a form element and to set value to input field require .val() method.



          So your code should look like



          $("#quantity2").keyup(function () 
          var value = $(this).val();
          $("#quantity_img2").val(value); // not .text()
          ).keyup();





          share|improve this answer

































            0



















            Use .val() in place of .text() like this



            $("#quantity2").keyup(function () 
            var value = $(this).val();
            $("#quantity_img2").val(value);
            ).keyup();


            Working fiddle






            share|improve this answer

































              0



















              I created a Jquery plugin called val2 that detects span vs input and just sorts out when to use $().text() vs. $().val(). After using val() on a span and wondering why it was broken only to slap forehead and say, "of course, dummy... its a span!" I created this plugin:



              $.fn.val2 = function (newVal) 

              // Jquery Plugin to improve upon $().val() and agnostically handle get/set of values for a span or input (type="text")
              // http://learn.jquery.com/plugins/basic-plugin-creation/
              // use, get mode: var val = $("#" + id).val2();
              // use, set mode: $("#" + id).val2("fred");

              if (this !== undefined)
              // newVal indicates set vs get mode
              if (newVal === undefined)
              var ret = "";
              if (this.attr("value") === undefined && this.prop("value") === undefined)
              ret = this.text(); // this is a span
              else
              ret = this.val(); // this would be an input
              return ret;

              else
              if (this.attr("value") === undefined && this.prop("value") === undefined)
              this.text(newVal); // this is a span
              else
              this.val(newVal); // this would be an input


              ;


              Usage Examples:



              Get mode:



              var txt = $("#MySpan").val2();
              var txt = $("#MyInput").val2();


              Set mode:



              $("#MySpan").val2("fred");
              $("#MyInput").val2("fred");





              share|improve this answer



























                Your Answer






                StackExchange.ifUsing("editor", function ()
                StackExchange.using("externalEditor", function ()
                StackExchange.using("snippets", function ()
                StackExchange.snippets.init();
                );
                );
                , "code-snippets");

                StackExchange.ready(function()
                var channelOptions =
                tags: "".split(" "),
                id: "1"
                ;
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function()
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled)
                StackExchange.using("snippets", function()
                createEditor();
                );

                else
                createEditor();

                );

                function createEditor()
                StackExchange.prepareEditor(
                heartbeatType: 'answer',
                autoActivateHeartbeat: false,
                convertImagesToLinks: true,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: 10,
                bindNavPrevention: true,
                postfix: "",
                imageUploader:
                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                allowUrls: true
                ,
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                );



                );














                draft saved

                draft discarded
















                StackExchange.ready(
                function ()
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f10884730%2fjquery-copy-form-inputs-with-keyup%23new-answer', 'question_page');

                );

                Post as a guest















                Required, but never shown


























                4 Answers
                4






                active

                oldest

                votes








                4 Answers
                4






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                4



















                To set the value of textbox element use val() method instead of text().



                Working demo http://jsfiddle.net/LnDYA/20/






                share|improve this answer


























                • Thanks this is this answer

                  – cantaffordretail
                  Jun 4 '12 at 16:33















                4



















                To set the value of textbox element use val() method instead of text().



                Working demo http://jsfiddle.net/LnDYA/20/






                share|improve this answer


























                • Thanks this is this answer

                  – cantaffordretail
                  Jun 4 '12 at 16:33













                4















                4











                4









                To set the value of textbox element use val() method instead of text().



                Working demo http://jsfiddle.net/LnDYA/20/






                share|improve this answer














                To set the value of textbox element use val() method instead of text().



                Working demo http://jsfiddle.net/LnDYA/20/







                share|improve this answer













                share|improve this answer




                share|improve this answer










                answered Jun 4 '12 at 16:31









                ShankarSangoliShankarSangoli

                64.8k11 gold badges78 silver badges119 bronze badges




                64.8k11 gold badges78 silver badges119 bronze badges















                • Thanks this is this answer

                  – cantaffordretail
                  Jun 4 '12 at 16:33

















                • Thanks this is this answer

                  – cantaffordretail
                  Jun 4 '12 at 16:33
















                Thanks this is this answer

                – cantaffordretail
                Jun 4 '12 at 16:33





                Thanks this is this answer

                – cantaffordretail
                Jun 4 '12 at 16:33













                2



















                $("#quantity_img2").text(value);


                should be



                $("#quantity_img2").val(value);


                DEMO



                Why this happen



                Because #quantity_img2 is an input field , a form element and to set value to input field require .val() method.



                So your code should look like



                $("#quantity2").keyup(function () 
                var value = $(this).val();
                $("#quantity_img2").val(value); // not .text()
                ).keyup();





                share|improve this answer






























                  2



















                  $("#quantity_img2").text(value);


                  should be



                  $("#quantity_img2").val(value);


                  DEMO



                  Why this happen



                  Because #quantity_img2 is an input field , a form element and to set value to input field require .val() method.



                  So your code should look like



                  $("#quantity2").keyup(function () 
                  var value = $(this).val();
                  $("#quantity_img2").val(value); // not .text()
                  ).keyup();





                  share|improve this answer




























                    2















                    2











                    2









                    $("#quantity_img2").text(value);


                    should be



                    $("#quantity_img2").val(value);


                    DEMO



                    Why this happen



                    Because #quantity_img2 is an input field , a form element and to set value to input field require .val() method.



                    So your code should look like



                    $("#quantity2").keyup(function () 
                    var value = $(this).val();
                    $("#quantity_img2").val(value); // not .text()
                    ).keyup();





                    share|improve this answer














                    $("#quantity_img2").text(value);


                    should be



                    $("#quantity_img2").val(value);


                    DEMO



                    Why this happen



                    Because #quantity_img2 is an input field , a form element and to set value to input field require .val() method.



                    So your code should look like



                    $("#quantity2").keyup(function () 
                    var value = $(this).val();
                    $("#quantity_img2").val(value); // not .text()
                    ).keyup();






                    share|improve this answer













                    share|improve this answer




                    share|improve this answer










                    answered Jun 4 '12 at 16:31









                    thecodeparadoxthecodeparadox

                    75.7k21 gold badges126 silver badges157 bronze badges




                    75.7k21 gold badges126 silver badges157 bronze badges
























                        0



















                        Use .val() in place of .text() like this



                        $("#quantity2").keyup(function () 
                        var value = $(this).val();
                        $("#quantity_img2").val(value);
                        ).keyup();


                        Working fiddle






                        share|improve this answer






























                          0



















                          Use .val() in place of .text() like this



                          $("#quantity2").keyup(function () 
                          var value = $(this).val();
                          $("#quantity_img2").val(value);
                          ).keyup();


                          Working fiddle






                          share|improve this answer




























                            0















                            0











                            0









                            Use .val() in place of .text() like this



                            $("#quantity2").keyup(function () 
                            var value = $(this).val();
                            $("#quantity_img2").val(value);
                            ).keyup();


                            Working fiddle






                            share|improve this answer














                            Use .val() in place of .text() like this



                            $("#quantity2").keyup(function () 
                            var value = $(this).val();
                            $("#quantity_img2").val(value);
                            ).keyup();


                            Working fiddle







                            share|improve this answer













                            share|improve this answer




                            share|improve this answer










                            answered Jun 4 '12 at 16:33









                            Prasenjit Kumar NagPrasenjit Kumar Nag

                            12.8k2 gold badges39 silver badges55 bronze badges




                            12.8k2 gold badges39 silver badges55 bronze badges
























                                0



















                                I created a Jquery plugin called val2 that detects span vs input and just sorts out when to use $().text() vs. $().val(). After using val() on a span and wondering why it was broken only to slap forehead and say, "of course, dummy... its a span!" I created this plugin:



                                $.fn.val2 = function (newVal) 

                                // Jquery Plugin to improve upon $().val() and agnostically handle get/set of values for a span or input (type="text")
                                // http://learn.jquery.com/plugins/basic-plugin-creation/
                                // use, get mode: var val = $("#" + id).val2();
                                // use, set mode: $("#" + id).val2("fred");

                                if (this !== undefined)
                                // newVal indicates set vs get mode
                                if (newVal === undefined)
                                var ret = "";
                                if (this.attr("value") === undefined && this.prop("value") === undefined)
                                ret = this.text(); // this is a span
                                else
                                ret = this.val(); // this would be an input
                                return ret;

                                else
                                if (this.attr("value") === undefined && this.prop("value") === undefined)
                                this.text(newVal); // this is a span
                                else
                                this.val(newVal); // this would be an input


                                ;


                                Usage Examples:



                                Get mode:



                                var txt = $("#MySpan").val2();
                                var txt = $("#MyInput").val2();


                                Set mode:



                                $("#MySpan").val2("fred");
                                $("#MyInput").val2("fred");





                                share|improve this answer






























                                  0



















                                  I created a Jquery plugin called val2 that detects span vs input and just sorts out when to use $().text() vs. $().val(). After using val() on a span and wondering why it was broken only to slap forehead and say, "of course, dummy... its a span!" I created this plugin:



                                  $.fn.val2 = function (newVal) 

                                  // Jquery Plugin to improve upon $().val() and agnostically handle get/set of values for a span or input (type="text")
                                  // http://learn.jquery.com/plugins/basic-plugin-creation/
                                  // use, get mode: var val = $("#" + id).val2();
                                  // use, set mode: $("#" + id).val2("fred");

                                  if (this !== undefined)
                                  // newVal indicates set vs get mode
                                  if (newVal === undefined)
                                  var ret = "";
                                  if (this.attr("value") === undefined && this.prop("value") === undefined)
                                  ret = this.text(); // this is a span
                                  else
                                  ret = this.val(); // this would be an input
                                  return ret;

                                  else
                                  if (this.attr("value") === undefined && this.prop("value") === undefined)
                                  this.text(newVal); // this is a span
                                  else
                                  this.val(newVal); // this would be an input


                                  ;


                                  Usage Examples:



                                  Get mode:



                                  var txt = $("#MySpan").val2();
                                  var txt = $("#MyInput").val2();


                                  Set mode:



                                  $("#MySpan").val2("fred");
                                  $("#MyInput").val2("fred");





                                  share|improve this answer




























                                    0















                                    0











                                    0









                                    I created a Jquery plugin called val2 that detects span vs input and just sorts out when to use $().text() vs. $().val(). After using val() on a span and wondering why it was broken only to slap forehead and say, "of course, dummy... its a span!" I created this plugin:



                                    $.fn.val2 = function (newVal) 

                                    // Jquery Plugin to improve upon $().val() and agnostically handle get/set of values for a span or input (type="text")
                                    // http://learn.jquery.com/plugins/basic-plugin-creation/
                                    // use, get mode: var val = $("#" + id).val2();
                                    // use, set mode: $("#" + id).val2("fred");

                                    if (this !== undefined)
                                    // newVal indicates set vs get mode
                                    if (newVal === undefined)
                                    var ret = "";
                                    if (this.attr("value") === undefined && this.prop("value") === undefined)
                                    ret = this.text(); // this is a span
                                    else
                                    ret = this.val(); // this would be an input
                                    return ret;

                                    else
                                    if (this.attr("value") === undefined && this.prop("value") === undefined)
                                    this.text(newVal); // this is a span
                                    else
                                    this.val(newVal); // this would be an input


                                    ;


                                    Usage Examples:



                                    Get mode:



                                    var txt = $("#MySpan").val2();
                                    var txt = $("#MyInput").val2();


                                    Set mode:



                                    $("#MySpan").val2("fred");
                                    $("#MyInput").val2("fred");





                                    share|improve this answer














                                    I created a Jquery plugin called val2 that detects span vs input and just sorts out when to use $().text() vs. $().val(). After using val() on a span and wondering why it was broken only to slap forehead and say, "of course, dummy... its a span!" I created this plugin:



                                    $.fn.val2 = function (newVal) 

                                    // Jquery Plugin to improve upon $().val() and agnostically handle get/set of values for a span or input (type="text")
                                    // http://learn.jquery.com/plugins/basic-plugin-creation/
                                    // use, get mode: var val = $("#" + id).val2();
                                    // use, set mode: $("#" + id).val2("fred");

                                    if (this !== undefined)
                                    // newVal indicates set vs get mode
                                    if (newVal === undefined)
                                    var ret = "";
                                    if (this.attr("value") === undefined && this.prop("value") === undefined)
                                    ret = this.text(); // this is a span
                                    else
                                    ret = this.val(); // this would be an input
                                    return ret;

                                    else
                                    if (this.attr("value") === undefined && this.prop("value") === undefined)
                                    this.text(newVal); // this is a span
                                    else
                                    this.val(newVal); // this would be an input


                                    ;


                                    Usage Examples:



                                    Get mode:



                                    var txt = $("#MySpan").val2();
                                    var txt = $("#MyInput").val2();


                                    Set mode:



                                    $("#MySpan").val2("fred");
                                    $("#MyInput").val2("fred");






                                    share|improve this answer













                                    share|improve this answer




                                    share|improve this answer










                                    answered Mar 28 at 22:04









                                    Jeff MerglerJeff Mergler

                                    6948 silver badges19 bronze badges




                                    6948 silver badges19 bronze badges































                                        draft saved

                                        draft discarded















































                                        Thanks for contributing an answer to Stack Overflow!


                                        • Please be sure to answer the question. Provide details and share your research!

                                        But avoid


                                        • Asking for help, clarification, or responding to other answers.

                                        • Making statements based on opinion; back them up with references or personal experience.

                                        To learn more, see our tips on writing great answers.




                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function ()
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f10884730%2fjquery-copy-form-inputs-with-keyup%23new-answer', 'question_page');

                                        );

                                        Post as a guest















                                        Required, but never shown





















































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown

































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown









                                        Popular posts from this blog

                                        Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                                        Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                                        Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript