there is this script:

$(function() { var $categoryWrap = $('#categoryWrap'); $categoryWrap.on('change', 'select', function () { var $this = $(this), category_id = this.value; $('#categoryIdInput').val(category_id); $this.nextAll().remove(); if(category_id == '0') { $('#typeCategory').remove(); $('#fieldsAdvert').remove(); return false; } $.ajax({ url: 'index.php?route=ajax/SubCategoryList', data: { id_cat: category_id }, type: 'POST', success: function(data) { $('#typeCategory').remove(); $('#fieldsAdvert').remove(); if (data != '') { var $newSelect = $('<select name="subCategory[]" class="subCategory" data-id="' + category_id + '"/>'); $newSelect.append('<option value="0">- <?=$text_select?> -</option>') $.map(data, function(v) { $newSelect.append('<option value="' + v.id + '">' + v.title + '</option>') }); $categoryWrap.append($newSelect); } } }); }); }); 

which works great, but, only after the site is fully loaded, how can I make the same script work the same way when the site is reloaded?

  • Use the localstorage , Luke! - user207618
  • the option with localstorage doesn't suit me, but thanks - vkt
  • one
    “Doesn't fit” is a rather weak argument. Crashed by this: "Choyta?". - user207618
  • one
    I'm sorry, but what's wrong? After F5, the script suddenly stops working? - Telion
  • @Other "Toit" that I do not need to use some data with this script and save it, but I need that after reloading the page (sorry for being common) the browser saw that the option was selected from select in the block <div id = "categoryWrap" > </ div> there are functions such as each, I don’t know how to write the beginning of this code with each, or do I need to duplicate the code and write each ?? - vkt

0