Good day, hello to all.

This is the day I ’m messing with fancybox and I can’t figure out how to transfer values ​​from a modal window to the page where the form was called from. The essence of the problem is that there is a page on which the city is selected. When you click on a city , a modal window pops up, where you need to select a city from the list by ticking (the option can be multiple), and then there is a button to choose . When you click on a button, select - the modal window should disappear and on the page instead of the label select a city - is replaced with the city selected from the list.

On the /index.php page, the modal window is called, html:

<div class="bl_categoty"> <div class="choice_category">Выбрать город</div> <div> 

here is js:

  $(".choice_category").fancybox({ 'padding':6, 'href':'/modal/categories.php', // события при закрытии формы применяется. beforeClose: function(){ console.log("форма закрыта"); $(".bl_categoty .value_heading").empty().text("ГОРОД"); } }); 

The modal window is in / modal/categories.php. On this page there is a list of cities and a button to select . When you click on it, it is necessary that the data is transferred to the /index.php page and substituted into .choice_category. The js code for the /modal/categories.php page is below:

 $(".action_category").click(function(event){ // value_heading должно записаться выбранный город. - не применяется $(".bl_categoty .value_heading").empty().text("ГОРОД"); parent.jQuery.fancybox.close(); // событие срабатывает // не применяется $('.choice_category').fancybox({ beforeClose: function(){ console.log("*******************"); $(".bl_categoty .value_heading").empty().text("ГОРОД"); } }); }); 

How can I transfer parameters from the modal window to the /index.php page

Thanks in advance for your reply. I would be very grateful for any help.

    2 answers 2

    Solved the problem

      $(".action_category").click(function(event){ var category = parent.document.getElementById("category_id"); category.value="Medved" parent.jQuery.fancybox.close(); }); 

      Your answer can be written as:

       parent.$('#category_id').val('Medved'); 
      • one
        Add a description of why your proposed option is better. And it seems to me that your code will not work (parent. $ Does not seem to be digested) - Ep1demic
      • This option is on jQuery, as opposed to the one proposed by JS, and it works) - Ruslan