Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Kervin
Starting Member
12 Posts |
Posted - 2003-06-24 : 23:51:47
|
| Hi.This is not an SQL related question, but you guys are so smart I thought I would try and sneak this one in. :-)Using Java Script in an ASP inviornment I am opening a modeless dialog window. I am using the parent window's window object through the dialog's dialogArguments to facilitate communication. I can update variables and access functions of the parent from inside the dialog in this fashion but I have not found a way to access functions and variables of the dialog from inside the parent. I need a way of identifying the dialog that has just been created from within the parent.Parent code:EnpNotesRet=window.showModelessDialog('../system/NotesFrame.asp',window);}Dialog code:var HoldParentwindowFunctions = window.dialogArguments;//inside the dialog there is a textbox called DialogNotes that I want to fill with the contents of a textbox form the parent called ParentNotes using the code belowdialogform.DialogNotes.value=HoldParentwindowFunctions.Parentform.ParentNotes.value.......The above works. Any ideas on what I need to do, to make it work going the other way? ThankxKervin.kervin_findlay@hotmail.com |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2003-06-25 : 00:18:40
|
| Well, I'll let ya slide on this one, but you're really better off posting this one in a JavaScript forum.Having said that, I have done a lot of stuff like what you're attempting, and basically you cannot access JavaScript objects, functions or variables in a child window from a parent. The only thing you can access from the parent are document elements in the child...divs, forms, frames, tables, etc. If it's not an HTML element, it's not accessible. One easy way to work around that is to have the JavaScript save variable values in hidden HTML elements, like a hidden <input> element or a div/span with its display set to "none". One of the tricks I used was to have a child frame download some data from a database and save it into a hidden div as a comma-separated string value (CSV). It would not display in the child window, and by putting it into a div I could grab it by using the innerText attribute. I could've also used an <input type=hidden> but you can only use its value attribute, and that can get messy with embedded quotes and spaces. This allowed me to download all the data I needed quickly and efficiently, and then use the parent frame to get the data and parse it using local JavaScript. The same applied to saving the data in the database, I'd combine it into a CSV using client JS and then send it to another framed page that was hidden. That way the main browser screen never had to post anything directly, never had to fully refresh, and I didn't have to deal with managing state each time I submitted the parent form.Also, many times I found it easier to have the child window update the parent, instead of having the parent try to query the child. The parent can't do certain things while the child window is still loading, but you can have the child simply run some of its own JS to push data into the parent. Believe it or not, it's actually better to have each page/window document be able to function on its own and not be dependent on other windows. That way they do their own thing, and then some client code can run after loading and do its own thing based on whether there's a parent or not.Check out some ASP and JavaScript sites, they're bound to have more details and options on this stuff. |
 |
|
|
Kervin
Starting Member
12 Posts |
Posted - 2003-06-25 : 00:42:50
|
| Thank you. You hit the nail on the head with what you said ( and I will post on the Asp/Java Script forums - this was just the first forum I have ever used and the response was so good I just got lazy ). Your answer is perfect but I need you to give me an idea of how you pass an HTML element from the parent to the dialog after it is opened. How do I identify the dialog window in the DOM? I need to name the dialog that I created first...so I can do something like:parentform.textfield.value = NewDialogName.textfield.valueIt almost sounds like I know what I am talking about but don't be fooled. I need help. In my example I give the return value variable a name of EnpNotesRet - can I repeatedly pull values through that until the dialog window is closed? What about multiple values ( without parsing a string ) I did try passing an array but could not get it working.ThankxKervin.kervin_findlay@hotmail.com |
 |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2003-06-25 : 07:23:24
|
| You're not actually passing the element, you're referring to an element in another window. The code you posted needs to be tweaked, and placed in the CHILD window:window.parent.parentform.textfield.value=NewDialogName.textfield.value;Something like that should work. It's better to have the child window refer back to the parent, for the reasons I mentioned earlier. The most you should have the parent do is simply open the child window.I should also mention that I've never used the showModelessDialog method, I've only used iframes. If you cannot refer to the newly opened window via the window or window.frames collection, I don't know if my suggestions will work. |
 |
|
|
|
|
|
|
|