View Full Version : Reload selectbox on parent modal from child

07-20-2007, 05:43 PM
1) Script Title: DHTML Modal window v1.01

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex8/dhtmlwindow/dhtmlmodal.htm

3) Describe problem:
Im pretty new to web programming, but I am catching on quickly. I am using the modal window and am having problems refering to the parent window from within the child window.
Scenario: From main window have textbox with button that opens a modal window using iframe with a form to select something out of inventory from 4 select boxes, which returns the selected item as a string to the textbox on parent window which works fine. On this first child window is another button that opens a 2nd modal window that again has a form that is used to add a new item to inventory that has one select box and 3 text fields. The select box has the same items as one of the select boxes from the first modal window. On this form I can add a new option to the select box using ajax, fill in text to the 3 textboxes and sumbit the form, which adds the new item to the database and closes this modal (the second child) window. When I get back to the first modal window, the select box that has the same items as in the 2nd child modal window, does not have the new option if created unless I refresh this modal window.

I would not like to have to refresh this modal window, manually or from its child. What I would like to do is from its child reload this select box, but I can't get the syntax correctly something I am missing not sure where to look.

On the 2nd child form, the process: click the submit new item button, which validates the form and on success returns true which posts the form, which I have a php script that will load the new item in the database, if that is successful I close the modal window.

Any help would be greatly appreciated, hope it makes sense.

07-20-2007, 07:12 PM
Well, I knew I was getting close, and I finally figured it out. Basically I didn't have the right calls in the right place. I just started working this week with AJAX and i have been intertwining php and js code. So I was trying to reload that select box in the child but I needed to do it in the onclose that was already in the parent and just run the AJAX function to reload. The next problem was loading the 4 select boxes with the selected option and 3 text boxes in the child form, and I was trying to access those but I was closing the window before reloading the fields after the post. In moving the close to the bottom of the script I was then able to get data from those fields to set the selected option in the 4 selects.

I am wondering something with this. After implementing some AJAX I have js code all over the place now. Would it be better to put all js code into functions that are in one file and always include that file in every page or keep the seperate js include files for site wide functions and page specific functions within the pages themselves.