Textbox value set by jquery is empty on save

6 posts, 0 answers
  1. Mattias
    Mattias avatar
    263 posts
    Member since:
    Aug 2012

    Posted 28 Feb 2013 Link to this post

    Hi,
    I set a textbox value from another textbox by jquery like this:
    $('input[id="Name"]').live('change keyup', function () {
       var urlSegment = $('input[id="UrlSegment"]');
       urlSegment.val("Test");
    });
    I can see the value "Test" in the second textbox but when clicking on save, the posted value is empty.
    I think the problem lies along with ajax cause when changing to server binding the value is posted.

    The form is generated in a popup by the grid.

    How do I solve this?

    Regards,
    Mattias
  2. todd
    todd avatar
    2 posts
    Member since:
    Apr 2011

    Posted 03 Mar 2013 Link to this post

    I'm having the same problem have you resolved this issue yet?
  3. Mattias
    Mattias avatar
    263 posts
    Member since:
    Aug 2012

    Posted 04 Mar 2013 Link to this post

    Hi Todd,
    It seems to work by adding .change() to the textbox.
    $('input[id="Name"]').live('change keyup', function () {
       var urlSegment = $('input[id="UrlSegment"]');
       urlSegment.val("Test");
       urlSegment.change();
    });

    /Mattias
  4. todd
    todd avatar
    2 posts
    Member since:
    Apr 2011

    Posted 04 Mar 2013 Link to this post

    Awesome that worked thanks!
  5. John
    John avatar
    6 posts
    Member since:
    May 2014

    Posted 14 Dec 2019 Link to this post

    Thank you so much!  I found this after hours of beating my head against the keyboard and it worked perfectly.
  6. Tsvetomir
    Admin
    Tsvetomir avatar
    757 posts

    Posted 17 Dec 2019 Link to this post

    Hello,

    When the jQuery val() method is used, the value of the input is visually changed. However, in order to have the same value applied in the model, you would have to manually trigger the change method so it would be indicated that the respective model's property has to be updated with the value of the input. Therefore, the provided suggestion above should be utilized:

    $('input[id="Name"]').live('change keyup', function () {
       var urlSegment = $('input[id="UrlSegment"]');
       urlSegment.val("Test");
       urlSegment.change();
    });

     

    Regards,
    Tsvetomir
    Progress Telerik

    Get quickly onboarded and successful with your Telerik UI for ASP.NET MVC with the dedicated Virtual Classroom technical training, available to all active customers.
Back to Top