Link to home
Start Free TrialLog in
Avatar of HairJam
HairJam

asked on

Passing values between Modal Dialog boxes using Javascript

Hi all,
I have an HTML page with a link on which calls a Modal Dialog box window. The Modal Dialog box window contains several form fields, however this Modal Dialog window also has a link on which calls another Modal Dialog window which contains a second set of form elements. What I am trying to do is pass data from a field from the second Modal window back into a field on the first Modal window, so that it can in turn be passed back to the HTML page.

So to clarify:
1. HTML Page (page1.html) calls "ModalDialog A".

2. "ModalDialog A" has a textfield within it called "ImageURL", there is also another link which calls "ModalDialog B".

3. "ModalDialog B" has a textfield within it called "txtFileName" and a form button.

When text is entered into "txtFileName" and submitted the value of this textfield needs to be sent back into the textfield "ImageURL" on "ModalDialog A".

Sending values to the HTML page from "ModalDialog A" is fine but I seem to have problems sending values between the two Modal windows - I would have though it was possible though.

Any help would be hugely appreciated.

Many thanks in advance,
Mike

Avatar of COBOLdinosaur
COBOLdinosaur
Flag of Canada image

We need to see code.

Cd&
Avatar of HairJam
HairJam

ASKER

Yep ok. I've tried to just give you the relevant code without all the other stuff.

The code that calls the first "ModalDialog A" within the HTML page is as follows:

<input type="button" tabIndex="50" value="Browse" onClick="window.showModalDialog('popups/insert_image.html', '', 'dialogWidth:450px; dialogHeight:315px; center:yes; scroll:no; resizable:no; status:no; help:no;');">

-------------------

This opens up "ModalDialog A" (insert_image.html) which has several textfields one of which is:
<form id="form1" name="form1">
<INPUT ID="txtFileName2" type=text style="left: 8.54em; top: 6.0647em; width: 21.5em;height: 2.1294em; " tabIndex=10 onfocus="select()" name="ImageURL">
</form>

and the second ModalDialog "ModalDialog B" (popup_imagestore.asp) is called by this button next to the above textfield:

<BUTTON ID=btnBrowse style="left: 31.36em; top: 7.5000em; width: 7em; height: 2.2em; " type=button tabIndex=50 onClick="window.showModalDialog('../../popup_imagestore.asp', '', 'dialogWidth:450px; dialogHeight:315px; center:yes; scroll:no; resizable:no; status:no; help:no;');">Browse</BUTTON>


--------------------


"ModalDialog B" now contains a select box with numerious entries pulled from a database. When the user clicks on an entry I need it to send that value back to "ModalDialog A" and insert it into the textfield called "ImageURL" - this is where I'm stuck.

<script language=javascript>
<!--
function SetPreviewImage(strUrl)
{
  opener.document.Form1.ImageURL.value = strUrl;
 // This is returning 'opener.document' is null or not an object
}
//-->
</script>

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" class="orangeBG">
<form name="imageContents">
<select name="FromList" size="12" class="field8"  onClick="SetPreviewImage(this.options[this.selectedIndex].value)">
<%
  Response.Write  strList
%>
</select>
</form>
</body>

-----------------------

Hope this helps, and hopefully I've not left anything out. If it doesn't make any sense though then let me know.
Mike
ASKER CERTIFIED SOLUTION
Avatar of COBOLdinosaur
COBOLdinosaur
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of HairJam

ASKER

Ok, I see what you're saying. I can certainly try using a conventional popup for "A" - it might work. I've read the other posts too and they also touch on a similar subject, so thanks for these.

I'll give the popup window a try first and then come back and let you know how I got on.

Thanks,
Mike
Avatar of HairJam

ASKER

I tried the conventional 'window.open()' route but that didn't resolve any of the problems - more honestly it created some elsewhere in the page.

Still the post you provided has helped me identify that my current route is a non-starter and I'm happy to close the post based on this. I've now looked into combining Modal A and B together and this has allowed me to progress somewhat.

Many thanks,
Mike
Sorry I didn't have a magic bullet.  Sometimes the browser manufacturers just don't consider what developers relly need to be able to do.  Thanks for the A. :^)

Cd&