Home  >  Q&A  >  body text

jQuery events don't provide synchronization of input values ​​from other inputs during form submission

<p><br /></p> <pre class="brush:php;toolbar:false;">$(document).ready(function () { $('#StaffNumber').on('keyup', function () { var staffNo = $(this).val(); $('#Username').val('EMP' staffNo); }); });</pre> <p>Here the username input is populated with a new value, but the value is not available when the form is submitted. Additionally, I need a field validation on the username that fires on submit even after the value is populated in a jQuery event. How to preserve the value of username?</p> <p><code>$('#StaffNumber').on('input', function () {...}); </code></p> <p><code>$('#StaffNumber').on('keyup paste', function () {...});</code></p> <p>I also tried the above activities, but still no value retained!</p>
P粉276876663P粉276876663445 days ago426

reply all(1)I'll reply

  • P粉394812277

    P粉3948122772023-08-02 10:16:58

    Make sure the event binding code is in $(document).ready(). Use change event instead of keyup for #StaffNumber input field. Combine the two keyup and change events if necessary. Check custom form submission handling and prevent default form submission behavior. Validate the form validation code to identify the updated value of Username.

    reply
    0
  • Cancelreply