How to retain the inputbox values when we click on back button | XM Community

How to retain the inputbox values when we click on back button

  • 8 November 2022
  • 2 replies
  • 329 views

Badge +2

Hi Community,
I'm trying to work with checkbox and input box, the function is to disable the input box when the checkbox is being check, however the problem is when the page back using back button even the checkbox is being check the input box are enabled. How to restore/retain the value
Here when the check is clicked/check the input boxes was disabled
back1.png
However, when I go back using back button even the checkbox is being clicked/check the input boxes is enabled
back2.PNG
The code for disabled the input boxes when the checkbox is being clicked

jQuery('input[type="checkbox"]').on("click",function(){
if(jQuery( "[id='checkboxid']" ).prop('checked')== true)
 {
jQuery('[id="inputboxid1"]').prop("disabled",true).val('');
jQuery('[id="inputboxid2"]').prop("disabled",true).val('');
jQuery('[id="inputboxid3"]').prop("disabled",true).val('');
jQuery('[id="inputboxid4"]').prop("disabled",true).val('');
}
else { 
  jQuery('[id="inputboxid1"]').prop("disabled",false);
jQuery('[id="inputboxid2"]').prop("disabled",false);
jQuery('[id="inputboxid3"]').prop("disabled",false);
jQuery('[id="inputboxid4"]').prop("disabled",false);
}
  });


2 replies

Userlevel 7
Badge +36

ricsdpl
Try writing the code on load for that page that if the checkbox is checked disable the text box. Which will execute even if you go back but not when you land on that page for first time.
Hope it helps!

Badge +2

Thank you Deepak!

Leave a Reply