473,464 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

script to open a new window and populate it with a single item from a list

TPK
Here is what I want to do with javascript.

On a page with text place a javascript link that:

1) When a user clicks the link (onClick) a new browser window opens
(the easy part) NewWindow =
window.open("windowpage.html","newWin","width=100, height=100")

2) Once the window is open I want to pull a specific item from a list
of items (array) and populate the open window with only that item. The
list of items would be in a separate .js file. Call it "definitions.js"

3) The (example) list of items (on definitions.js) has a list of terms
and definitions:

Example List:
TermArray = new Array();
DefinitionArray = new Array();

TermArray[0] = "Stop Sign"
DefinitionArray[0] = "Stop Sign: A red sign with the word STOP.";

TermArray[1] = "Yield Sign"
DefinitionArray[0] = "Yield Sign: A yellow sign with the word YIELD.";

TermArray[2] = "Go Sign"
DefinitionArray[0] = "Go Sign: A green sign with the word GO.";

TermArray[3] = "Right Turn Sign"
DefinitionArray[0] = "Right Turn Sign: A white sign with an arrow
pointing RIGHT.";

4) The new browser window can then be closed by clicking a
"javascript:window.parent.close()" link.

So basically I'd like to pass a variable, but I'm not exactly sure
how structure the script on the referring page/link.
Can anyone send me a link to a resource that would describe doing this
or can show me the script?

Thank you,
TPK

Feb 14 '06 #1
1 1622
The cleanest way to pass a variable is to send it as part of the URL.

for example, your link would be:
<a href="#" onclick="describe('Stop Sign');">Stop Sign</a>

your javascript on the main page would be:

function describe(term) {

window.open("windowpage.html?"+term,"newWin","widt h=100,height=100")
}

(essentially the URL of the window that pops open would be
"windowpage.html?Stop%20Sign")

The scripting in that window, looks for the term after the '?' in the
URL like this:

var term = location.href.substring(location.href.indexOf("?") +1);
// essentially everything the "?"

then look up the term in your array.

By the way, your definitions arrays would probably work out better if
they were like this instead:

DefinitionArray = new Array();
DefinitionArray["Stop Sign"] = "Stop Sign: A red sign with the word
STOP.";
DefinitionArray["Yield Sign"] = "Yield Sign: A yellow sign with the
word YIELD.";
DefinitionArray["Go Sign"] = "Go Sign: A green sign with the word GO.";
DefinitionArray["Right Turn Sign"] = "Right Turn Sign: A white sign
with an arrow pointing RIGHT.";

That way you can then use:

document.write(DefinitionArray[term]);

Feb 14 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Fox | last post by:
I merged and modified these script which work perfectly fine as long as I use server.execute to access the VBS part (which is itself in another ASP file). When these I use a session variable to...
2
by: Maik | last post by:
I Need a popup-killer script
2
by: Dennis | last post by:
This may be easy for most but I can't get this thing to work. I believe I followed all the instructions but when I click on the link no window opens just the default IE page cannot display. Here is...
0
by: Tom Dacon | last post by:
"Open .Net Command Window Here" context menu for Windows Explorer: The reg file described below adds a new menu item to Windows Explorer's context menu when you right-click over a folder (or the...
7
by: Joker7 | last post by:
Hi, This is still giving me a big problem !! Maybe if I post the original code here it may be of more help as the above will/is not working. $link = "<a
0
by: ZMan | last post by:
Scenario: This is about debugging server side scripts that make calls to middle-tier business DLLs. The server side scripts are legacy ASP 3.0 pages, and the DLLs are managed DLLs...
7
by: kelly | last post by:
Hi I have an app where I have 2 dropdown lists (state and city) and a Save button. When a user selects a value from the state dropdown list, I use script callback to populate the data for the...
2
by: vmalhotra | last post by:
Hi I am new in python scripting. I want to open a Multiple telnet session through once script. In other way i can tell i want to open two linux consoles through one script. I wrote one...
1
by: ehud37new | last post by:
this script work fine in IE but not in FireFox where is the problem? here is the script /*------------------------------------------------------------------ File: menu.js ...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.