Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > script to open a new window and populate it with a single item from a list

Reply
Thread Tools

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

 
 
TPK
Guest
Posts: n/a
 
      02-14-2006
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

 
Reply With Quote
 
 
 
 
somejeff@gmail.com
Guest
Posts: n/a
 
      02-14-2006
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]);

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Open a new window on top of parent window using script Ralf ASP .Net 2 11-15-2006 09:45 PM
Populate a popup window with clickable records from an Access DB and upon clicking, populate a selectbox on the original webpage with the clicked record Enjoy Life ASP General 2 02-23-2005 10:48 PM
Selecting list item to auto-populate text fields Dave HTML 1 01-25-2005 01:04 PM
Not able to populate and select an item in a list dynamically? Hel =?Utf-8?B?UmV6YSBTb2xvdWtp?= ASP .Net 1 08-25-2004 05:40 PM
Change style of a single row of the item list of datagrid, based on a field value of current item... QUASAR ASP .Net Datagrid Control 6 01-17-2004 07:46 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57