Solved

Setting the value of a text box using jQuery

Posted on 2014-11-30
3
200 Views
Last Modified: 2014-11-30
I have the following code:

        $(document).on('change', '#repeaterContainer select', function () {
            if ($(this).attr('targetcontrolid') == "tbShippingInstructions") {
                alert(this.value);
            }
        });

Open in new window


Works great. In trying to set this.value to a textbox, I'm trying this:

       $(document).on('change', '#repeaterContainer select', function () {
            if ($(this).attr('targetcontrolid') == "tbShippingInstructions") {
                var x = this.value;
                $('#tbShippingInstructions').val(x);
            }
        });

Open in new window


This doesn't work. how do I set the value of a text box names tbShippingInstructions to this.value??
0
Comment
Question by:mwmiller78
3 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 40472650
       $(document).on('change', '#repeaterContainer select', function () {
            if ($(this).attr('targetcontrolid') == "tbShippingInstructions") {
                var x = $(this).val();
                $('#tbShippingInstructions').val(x);
            }
        });

Open in new window

0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 40472659
       $(document).on('change', '#repeaterContainer select', function () {
            if ($(this).attr('targetcontrolid') == "tbShippingInstructions") {
                var x = $(this).val();
                $(':text[name*=tbShippingInstructions]').val(x); // name attribute
            }
        });

Open in new window

0
 

Author Closing Comment

by:mwmiller78
ID: 40472692
Perfect, thanks!
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question