Hi,
In one window by clicking a button(button name select) a pop up window, in that pop up window , I have only lot of check boxes.
My query is,
I want to show what are the values I selected in the pop up window that should display in the previous window near to the select button with sepearate comma,

Dani AI

Generated

: the simplest reliable pattern is to collect the checked values in the popup, turn them into a comma-separated string, then send that string back to the opener window. was right that you can talk to the parent window when both pages share the same origin. Below are two concise ways: (A) call a function exposed on the opener, or (B) update an element in the opener directly.

Opener (page that opened the popup):

<button onclick="window.open('popup.html','sel','width=400,height=400')">Select</button>
<span id="selectedList">None</span>

<script>
function receiveSelection(csv) {
  // Use textContent to avoid injecting HTML
  document.getElementById('selectedList').textContent = csv || 'None';
}
</script>

Popup (collect checked boxes and send back):

<!-- checkboxes with values -->
<button id="done">Done</button>

<script>
document.getElementById('done').addEventListener('click', function () {
  var checked = Array.prototype.slice.call(
    document.querySelectorAll('input[type=checkbox]:checked')
  ).map(function (c) { return c.value; });
  var csv = checked.join(', ');
  if (window.opener && !window.opener.closed) {
    try {
      window.opener.receiveSelection(csv); // same-origin direct call
    } catch (e) {
      // fallback: send via postMessage (useful for cross-origin scenarios)
      window.opener.postMessage({ selected: csv }, '*');
    }
  }
  window.close();
});
</script>

Notes and troubleshooting:

  • Same-origin is required for direct access. Use window.postMessage on both sides if the popup is cross-origin.
  • Open the popup in response to a user click to avoid popup blockers.
  • Use textContent (not innerHTML) when inserting values to avoid XSS.
  • Check that the opener is not already closed and that the function name matches.
  • If nothing appears, add console.log checks in both windows to verify data flow.

Recommended Answers

All 2 Replies

as long as you dont violate any cross domain rules you can access your parent page through js

parent."somejsfunc"(selected checkbox values)

I can`t understand. tell me briefly

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.