Search code examples
c#jqueryasp.net-mvc-4razor-2

Communication between two pages to allow a popup to select Customer ID


I have a purchases form that requires you to select a customer ID, currently it is just a dropdown list of Customer Names with their ID hidden.

What I want to do is instead of a dropdown list, there will be a hyperlinked select button that when clicked will open a popup box that allows them to search through a list of customers using whatever field they choose.

Now I have had no problem with making the popup box search through for a customer, I just don't know how to pass that data back to the main page. Are there any examples for this?


Solution

  • There are some ways to send data from popup window to opener window:

    1) use window.opener property in popup window:

    function pick(data) {
      if (window.opener && !window.opener.closed)
        window.opener.document.anyForm.anyInput.value = data;
      window.close();
    }
    

    2) More exotic: use local storage to handle custom events from other window

    look at sample