How to keep elements hide() show() states on page load?

How to keep elements hide() show() states on page load?

Hello,

I have a CRUD in PHP where the user selects 2 options in a dropdown menu, based on the select 1 field or another shows up where the user input a number.

My problem is this:

If the user choose choice 2 which shows input 2 and send the information to my databasem on the next page load the php will show the choice 2 but the input will not show up until I click again on the dropdown menu...

How to get jquery to load automatically based on the dropdown selection please?


Here is my code:

  1. $j(document).ready(function(){

  2. //Hide these 2 elements when the page is loaded
  3. $j("#quantity").hide();
  4. $j("label[for='quantity']").hide();


  5. //When user changes the dropdown menu state show this or that...
  6. $j('#prize_quantity').on('change', function() {
  7. if ( this.value == 'Limited')
  8. {//The below code is not changing until I select again "Limited" via the dropdown menu..
  9. $j("#quantity").show();
  10. $j("label[for='quantity']").show();
  11. $j('#quantity').attr('required', true)
  12. }
  13. else
  14. {
  15. $j("#quantity").hide();
  16. $j("label[for='quantity']").hide();
  17. }
  18. }).change();
  19. });
Thanks!

Ben