1

Sorry but I don't know how to ask this better.

This is my main page:

caller window image

when I select the "New Element" option from the select element, a popup window (or whatever is named) should open:

popup window image

After the form is completed, the submit button should perfom a POST to the server in order to insert a new element in the Data Base, the popup window should close automatically and the dropdown list must be selected in the newest inserted element

caller window with the updated select element

THE POPUP WINDOW IS NOT PART OF THE DOM of the main page.

How could I do this in jQuery? The popup window is a web page that will have to be loaded some how. I guess that I should do a jQuery.post() to send the data from the popup window to the server.

Thanks in advance!

Lucas
  • 1,239
  • 4
  • 15
  • 26

1 Answers1

1

You can use window.open() for this, and use querystrings to populate your popUp window.

So your select box would look something like this:

 <select onChange="popUp(this.value);">
   <option value="0">New Element</option>
   <option value="1">Element 1</option>
   <option value="2">Element 2</option>
   <option value="3">Element 3</option>
 </select>

Then your popUp() function would look like this:

 function popUp(val) {
   window.open('mypopupwindow.php?element=' + val,'_target','width=400,height=400');
 }

I would use some sort of server side language on mypopupwindow.php , otherwise you would need to use javascript to read the querystrings in the url to populate your text box.

Control Freak
  • 12,965
  • 30
  • 94
  • 145
  • thanks Zee, I understand that this code is for opening the popup window but the real important thing is to update the dropdown list of the caller page with the element inserted from the popup window. – Lucas Jul 04 '12 at 22:31
  • As I said, you would populate the url with Querystrings `url?querystring=value` and then would read that querystring in your popup window either using a server-side language, or javascript as seen here: http://stackoverflow.com/questions/901115/get-query-string-values-in-javascript – Control Freak Jul 04 '12 at 22:32
  • Zee, I'm testing your suggestion but I don't need to populate the popup windows. What I need is to 're populate' the select element in the page that calls the popup, with the new element inserted in the popup window.. – Lucas Jul 04 '12 at 22:55
  • 1
    Actually, view this http://stackoverflow.com/questions/1034903/jquery-write-to-opener-window – Control Freak Jul 04 '12 at 23:05
  • Thanks Zee, it was what I needed.I wish I could set your comment as the accepted answer =) – Lucas Jul 04 '12 at 23:50