Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

window.open() called from a dropdown list

Status
Not open for further replies.

MikCohen

Technical User
Mar 17, 2004
3
AU
Hello, just a quick Q for someone more experienced.
I am trying to open a new browser window (in this example a pdf) from a an item selected in a form (combobox/dropdown list).
Just include a pdf called test.pdf in the same directory. It works outside of the form but now when called from within. Please help!

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Test</title>

<script language="JavaScript">
function selectIndex(selObj) {
ref = selObj.options[selObj.selectedIndex].value;
openWindow(ref);
}
function openWindow(ref) {
alert(ref); <!-- works ok to here -->
newWin = window.open(ref, "Test", " statusbar,menubar,toolbar,dependant,resizable,scro
llbars,titlebar");
}
</script>
</head>

<body>

<form name="formIndex" id="formIndex">
<select name="menu" onChange="selectIndex(this)">
<option value="" id="">click below</option>
<option value="test.pdf" id="test">Test</option>
</select>
</form>

<p>But here it works - <a href="javascriptpenWindow('test.pdf')">Test</a></p>

</body>
</html>

 
Works fine for me in ie6. What browser are you using?


ASCII silly question, get a silly ANSI
 
I use IE6.0.2800

I cant believe that the pdf loads (window.open()) works from the form.

Mik...
 
I think it's a path thing.

The href has an implied path (the current directory). The window.open method has no such implied path.

Change your value="test.pdf" to value=" (obviously replacing the correct path) and that should work for you.

Hope this helps,
Dan
 
No, this is not the problem.

I do concede that the code works fine but in my haste to create a sample of how I used the code I must have missed some subtlety.

I have a "go" button next to the list. If I select from the dropdown list or the go button I end up with the same parameters at openWindow(). However the returned window is null when from the list and ok when from the button. The button fn simply calls the list handler fn. That simple and that confusing???

Perhaps becausse the Form is in a frame (within 2 framesets) - I have to test. If I can come up with some sample code where it fails I will repost.

Thanks - Mik...
 
Aaah... Try changing this:

Code:
onChange="selectIndex(this)">

To this:

Code:
onChange="selectIndex(this.options[this.selectedIndex].value);">

Hope this helps,

Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top