Javascript Keyup Not Working When User Hits Back Button

30 Views Asked by At

I have this piece of Javascript inside a (document).ready function. What it does is it makes the text field #rollover_cash_wire_ffc1 field set to readonly as well as populates the field with the value of the #payee_account text field when a value is entered there.

$('#payee_account').on('keyup', function() { $('#rollover_cash_wire_ffc1').val($(this).val()).attr('readonly', true); });

It works when the page is initially loaded. However, if the user hits the 'back' button on their browser after going to the next step in the process, the keyup function no longer seems to work. The field is set to readonly but it does not get populated with the value from #payee_account if it gets changed.

I was expecting this script to behave the same way regardless if the user enters the page for the first time or gets there by hitting the back button.

I have tried changing the function to .on('change') and that did not make a difference. I have also tried storing the value in local storage when the field changes like this localStorage.setItem('taxable_cash_wire_account_number', $(this).val()); and that also didn't make a difference.

0

There are 0 best solutions below