Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    mtd
    mtd is offline
    Regular Coder
    Join Date
    Jun 2003
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Select Box Pop-up Code help

    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:
    Code:
    <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!!!

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    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)
    Code:
    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.
    Code:
    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();
    	}
    }
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #3
    mtd
    mtd is offline
    Regular Coder
    Join Date
    Jun 2003
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thanks!

    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •