...

View Full Version : Select Box Pop-up Code help



mtd
01-31-2005, 01:11 AM
I am trying to put together a script that will launch a popup window from a user's selection from a selct box (aka dropdown menu). Here is what I have so far:


<script type="text/javascript">
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=350,height=500,left = 100,top = 100');");
}
</script>


<form name="stores_storedepartments_seafood">
<select name="seafood_options" class="extra_info_1" onChange="popUp(this)">
<option selected>Choose an option....</option>
<option>- - - - - - - - - - - - - - - - - - - - - -</option>
<option value="http://www.msn.com/">Fillets</option>
<option value="http://www.yahoo.com/">Shrimp</option>
<option value="http://www.apple.com/">Seafood Hors D'euvres</option>
<option>- - - - - - - - - - - - - - - - - - - - - -</option>
</select>
</form>


This (obviously) is not working. I am not very learned in JavaScript, so it may be an obvious answer that I am just overlooking.

I also foresee these problems in the future with the current method of implementation:
- multiple slect boxes/forms on one page: will one instance of the code handle multiple forms?
- the <option>s with no value ("Choose an option...", "- - - - - -"): will it return an error? It should just do nothing...

I know I am probably asking a lot, but I am overwhelmed and don't know where to start. Thanks in advance!!!

glenngv
01-31-2005, 02:43 AM
If you will use the window handle of the opened popup later in another function, instead of using eval, use the window object to make the variable global. (See the square bracket notation link in my sig for more info)

function popUp(oSel) {
var url = oSel.options[oSel.selectedIndex].value;
if (url){
var day = new Date();
var id = day.getTime();
window["page" + id] = window.open(URL, id, 'toolbar=0, scrollbars=1, location=0, statusbar=0, menubar=0, resizable=1, width=350, height=500, left=100, top=100');
window["page" + id].focus();
}
}
But if you will not use it later, just keep it local.

function popUp(oSel) {
var url = oSel.options[oSel.selectedIndex].value;
if (url){
var day = new Date();
var id = day.getTime();
var page = window.open(URL, id, 'toolbar=0, scrollbars=1, location=0, statusbar=0, menubar=0, resizable=1, width=350, height=500, left=100, top=100');
page.focus();
}
}

mtd
01-31-2005, 09:06 PM
Thanks glenngv - worked like a charm! I opted to go with the local version, plus if I ever need to change it it is easy enough because it is located in an external .js

Side note: I did have to change a small bit:

var page = window.open(URL, id, etc...

needs to become

var page = window.open(url, id, etc...

("url" case change), in order to match the new code above it
Just in case anyone else reads this post....

Anyway, thanks again!!! The extra info in your sig. helped too!

mtd



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum