Forms, Popups, and Javascript functions - How do I open a popup window from a javascript function?

They have: 15 posts

Joined: Sep 1999

How do I open a popup window from a javascript function? The following code and
function below allows the user to make a selection from 2 radio button choices. The HREF
link passes that chocie to a javascript function and then the link is called.

This all works very well, but I want the choice that points to a text link, to open up in a
popup window and leave the calling window open. Now that I have the link choices in a
javasript function, I cannot seem to get my text link (text.htm) located in the function,
to open up in a popup window.

Can anybody make any suggestions?

The function below is located between the <HEAD> and </HEAD> tags.

function navigate() {
if (document.radioForm.selection[0].checked) {
window.location.href = "audio/sound.wav";
}
else {
window.location.href = "popups/text.htm";
}
}

And this form located in the <BODY> and </BODY> tags.

<form name="radioForm">

<input name="selection" type="radio" checked>Choice 1
<input name="selection" type="radio"> Choice 2

<a href="javascript:navigate()">
<img src="graphics/button.gif"></a>

Any help would be greatly appreciated!

Ray

John Pollock's picture

He has: 628 posts

Joined: Mar 1999

Try:

function navigate() {
if (document.radioForm.selection[0].checked) {
window.open('audio/sound.wav');
}
else {
window.open('popups/text.htm');
}
}

You can add a bunch of options as well for width, height, menus, and such. I have these listed in a tutorial at:
http://www.pageresource.com/jscript/jwinopen.htm

Hope this helps! Smiling

----------
Page Resource: http://www.pageresource.com
JavaScript City: http://www.javascriptcity.com

They have: 15 posts

Joined: Sep 1999

John -

Hey!! Your suggestion worked beautifully!! I appreciate the response - as well as the link to your tutorial. I've bookmarked it for further reference because I suspect I am going to need it alot!! Thanks again for helping me get over a hurdle John!

Ray

They have: 5,633 posts

Joined: Jan 1970

If you want to customize the new window then play around with the following code.

function newWindow() {
var windowFeatures;
windowFeatures = 'height=400,width=400,'
windowFeatures += 'screenX=5,screenY=5,top=5,left=5,'
windowFeatures += 'location=no,menubar=no,'
windowFeatures += 'resizable=yes,scrollbars=no,'
windowFeatures += 'status=no,toolbar=no'
window.open('URL','WINDOW NAME',windowFeatures);
}

----------
[email protected]
http://go.to/hass

They have: 15 posts

Joined: Sep 1999

Thanks Lloyd!! I'll experiment with the extra code you gave me - it's great to have customizable options ... Many thanks again! I hope I can get good enough at this to return the favor someday!

Ray

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.