Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
| Search | Today's Posts | Mark Forums Read
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript 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 March 2nd, 2005, 10:09 AM
Registered User
 
Join Date: Mar 2005
Location: Edinburgh, SCotland, United Kingdom.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default manipulating content in new window

Hello,
I am writing an online tutorial with a quiz at the end. For each question in the quiz(just a regular checkbox form)clicking a button opens the answer and explanation in a new window. I'm trying to then manipulate the explanation depending on which boxes the user checked, to give a context-dependent explanation.

This works up to a point except for the first time the new window is opened. Usually (but not always) the first time the answer is accessed it is inaccessible to the javascript and is not manipulated. Repeatedly clicking on the " get answer" button solves this. Does anyone have an idea how to fix this? I'm using PC IE5.5
here is the relevant code:

function get_answer(box_name) {
// open a new window
ans_win = window.open(answ_html, "answer", "width=500,height=250");
// this just gets a <p>tag containing the "basic" text
para = ans_win.document.getElementById(box_name);
//para is often null the 1st time this function is called
//why is it inaccessible?
if(String(para) == "null") {alert("para is null")}
}
MAny thanks for any replies, I've been banging my head for a day or 2 on this now.
 
Old March 2nd, 2005, 10:27 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

It's probably because the document has not finished loading. You can use setInterval to introduce a delay and only start accessing the document once ans_win.document is not null.

--

Joe (Microsoft MVP - XML)
 
Old March 2nd, 2005, 10:51 AM
Registered User
 
Join Date: Mar 2005
Location: Edinburgh, SCotland, United Kingdom.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

great, thanks a lot, that solution works perfectly.
Richard





Similar Threads
Thread Thread Starter Forum Replies Last Post
Open new window with content blkskullwork Javascript 5 January 24th, 2007 12:50 PM
Choosing content depending on content of other ele dsekar_nat XSLT 1 February 27th, 2006 05:58 AM
Manipulating strings dzisaacs XSLT 2 December 27th, 2005 10:52 AM
Manipulating Processes ? kush28 C# 1 October 26th, 2005 04:49 AM
Manipulating DataColumn BSkelding VB.NET 2002/2003 Basics 1 January 28th, 2005 12:11 PM





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