PDA

View Full Version : Drop-down menus -- opening file in new window


dmk
12-10-2002, 05:28 PM
I'm not sure where I got this code (attached) but it has served me well over the last 3 years. But I need help with it now.

My webpage is done in 3 frames. The drop-down menus are in Frame 2 and the menu items open in Frame 3. I want one of my menu items to open in a new window (instead of in Frame 3), and that's what I need help with. (I'm linking to an Excel spreadsheet and it doesn't print correctly if the file opens in a frame.) Can someone tell me how to modify the existing code?

Thanks.

d

brothercake
12-10-2002, 05:31 PM
Two things:

var selection = list.options[list.selectedIndex].value

should be

var selection = list.options[list.options.selectedIndex].value

for cross-browser. For your question, you can open in a new window by changing

parent.body.location.href = selection

to

open(selection);

dmk
12-10-2002, 05:35 PM
Won't that change the behavior of all of the menu items? I want all but one to continue opening in Frame 2. Can I change it for just one of the "option value" items?

PauletteB
12-10-2002, 11:28 PM
Try<script language="JavaScript" type="text/javascript">
function JumpToIt (list) {
var selection = list.options[list.selectedIndex].value
if (selection == "http://dk_intranet/FinanceDept/ExpenseRptOld.xls") {
window.open(selection)
}
else parent.location = selection
}
</script>

<form>
<select onChange="JumpToIt(this)" size="1" name="Finance"
style="font-family:Arial; font-size:8pt; position:relative; width:150px">
<option value="javascript:void(0)" selected
>Select from list</option>
<option value="http://dk_intranet/link_pg_finance_dept.htm"
>Finance Department</option>
<option value="http://dk_intranet/FinanceDept/BillCover.pdf"
>Bill Cover Ltr Instructions</option>
<option value="http://dk_intranet/NoCheck.htm"
>Check Request</option>
<option value="http://dk_intranet/FinanceDept/ExpenseRptOld.xls"
>Expense Report</option>
</select>
</form>

dmk
12-11-2002, 05:02 PM
That works in that it opens the desired file in a new window, but the Else part of the statement (parent.location = selection) makes every other page open over all three frames of the page. If you hit the X to close, you close the web page. Instead of "selection," I think I need something that refers to my Frame 3. (I want the other pages to open into Frame 3.)

Thanks.

dmk
12-11-2002, 05:11 PM
:thumbsup: Never mind my previous post. I actually was able to figure this out myself! The line I needed in this case was:
else parent.body.location.href = selection
Thanks.

dmk
12-11-2002, 05:28 PM
:o Okay, now I'm embarrased. This line of my code:

<option VALUE="http://dk_intranet/link_pg_admin.htm" selected>Administration

would mean that the top value of the menu would always be selected (the menu line showing would snap back to that item after you chose one of the menu items and moved to it). Now I have this line in my code:

<option value="javascript:void(0)" selected>Finance Department---></option>
<option value="http://dk_intranet/link_pg_finance_dept.htm"

and the selected menu item remains the last one the user chose. Can we change that?

PauletteB
12-11-2002, 11:58 PM
You can remove the focus from the last selection with:
<select onChange="JumpToIt(this); this.blur()", but this will not change the selection to a desired option. Don't know if / how it can be done without a reload, or a different script.