Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 29th, 2003, 04:03 PM
Registered User
 
Join Date: Aug 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to wjenkins
Default How to post data to window opener

Hi;
I've got a window in a frame that opens another window when a choice is selected in a select list. This new window gathers some information and then is supposed to post it back to a specific field on the window that opened this window in the first place. But the javascript to post the data back to the opener doesn't work. The line that is having the problem is this:

opener.document.form.getElementById("MenuExtraChg["+Index+"]").value=99.9;

(I've hard-coded the number and for simplicity.)
I've also tried reading from the parent form in a similar manner and that doesn't work either:

myVal = opener.document.form.getElementById("MenuExtraChg["+Index+"]").value;

Help please!
 
Old August 30th, 2003, 10:54 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Can you show the actual lines of code as what you posted here looks ok in theory?

--

Joe
 
Old August 30th, 2003, 11:13 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

The getElementById method just belongs to the document, and is not a method of the form object. Remove the form. to have your code look like this:

Code:
myVal = opener.document.getElementById("MenuExtraChg["+Index+"]").value;
Does that help??

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old August 30th, 2003, 03:40 PM
Registered User
 
Join Date: Aug 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to wjenkins
Default

Thank you so VERY much! That worked beautifully!:D

Since you seem to be a helpful sort, I have one other little problem...

In my parent form, I have an array of textareas that I can't seem to access from javascript. Here's what I have (doesn't work):

document.getElementById(\"MenuItemComment[\"+MenuIndex+\]\").value=\"Nothing Entered\";\n";

I need to also access the same field from the child screen.
Thanks for your help so far!


 
Old August 30th, 2003, 03:49 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Helpful sort?? Hmmm, not sure whether that is good or not.... ;)

Anyway, below you'll find an example that builds an array of textareas on the page and then loops through it alerting each value of the area. Notice that it isn't very cross browser as it uses getElementById and getElementsByTagName.....

Cheers,

Imar

Code:
<html>
    <head>
        <title>Array of Text Areas</title>
        <script language="JavaScript">
            function OnLoad()
            {
                var allTextAreas;
                // get a reference to all <textarea> tags in the page
                if (document.all || document.getElementsByTagName) 
                {
                    allTextAreas = document.getElementsByTagName("textarea");
                }
                else 
                {
                    document.write("Unrecognized Browser Detected");
                }
                // If there are textareas
                if (allTextAreas.length > 0)
                {
                    for (i = 0; i < allTextAreas.length; i++)
                    {
                        alert(document.getElementById(allTextAreas[i].id).value);
                    }
                }
            }
        </script>
    </head>
<body onload="OnLoad();">
<textarea id="txt1">Text 1</textarea>
<textarea id="txt2">Text 2</textarea>
<textarea id="txt3">Text 3</textarea>
</body>
</html>
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.





Similar Threads
Thread Thread Starter Forum Replies Last Post
window.opener for mozilla jun99 Javascript 3 September 1st, 2009 08:57 AM
Problem accessing the window.opener.opener maryuob Javascript 3 January 18th, 2006 05:25 AM
can you get window.opener data in server side code edmicman Javascript 3 August 27th, 2005 03:41 AM
window.opener help fs22 Javascript How-To 6 May 9th, 2004 10:50 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.