Results 1 to 3 of 3

Thread: Adding a popup function to dropdown menu

  1. #1
    Join Date
    Jun 2006
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Arrow Adding a popup function to dropdown menu

    1) Script Title: Drop down menu w/ description

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...bodescribe.htm

    3) Describe problem: Is there any way for me to use the selection list to launch a sized popup window? Basicaly what I need is to have each menu item to be launched in a popup window of a different size when the user selects it and presses GO

    I can do this for normal links using the popup generator (on DHTML) but I also need this for the dropdown list since it greatly reduces the size of bigger listed menus.

    Thanks,
    Aku

  2. #2
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    Sure, try the below modified script, which lets you optionally specify the pop up window's size when using target="newwin" to get it to open in a new window:

    Code:
    <!--Example drop down menu 1-->
    
    <form name="form1">
    <select name="select1" size="1" style="background-color:#FFFFD7" onChange="displaydesc(document.form1.select1, thetext1, 'textcontainer1')">
    <option selected value="http://www.javascriptkit.com">JavaScript Kit </option>
    <option value="http://freewarejava.com">Freewarejava.com</option>
    <option value="http://wired.com" target="newwin">Wired News</option>
    <option value="http://www.news.com" target="newwin" class="500 by 600">News.com</option>
    <option value="http://www.codingforums.com" target="newwin">Coding Forums</option>
    </select>
     <input type="button" value="Go" 
    onClick="jumptolink(document.form1.select1)"><br>
    <span id="textcontainer1" align="left" style="font:italic 13px Arial">
    </span>
    </form>
    
    <!--Example drop down menu 2-->
    
    <form name="form2">
    <select name="select2" size="1" style="background-color:#E3FFDF" onChange="displaydesc(document.form2.select2, thetext2, 'textcontainer2')">
    <option selected value="http://www.cnn.com">CNN</option>
    <option value="http://www.msnbc.com">MSNBC</option>
    <option value="http://news.bbc.co.uk">BBC News</option>
    <option value="http://www.theregister.com/">The Register</option>
    </select>
     <input type="button" value="Go" 
    onClick="jumptolink(document.form2.select2)"><br>
    <span id="textcontainer2" align="left" style="font:italic 13px Arial">
    </span>
    </form>
    
    
    
    <!--IMPORTANT: Below script should always follow all of your HTML codes above, and never proceed them-->
    <!--To be safe, just add below script at the end of your page-->
    
    <script type="text/javascript">
    
    /***********************************************
    * Drop down menu w/ description- &#169; Dynamic Drive (www.dynamicdrive.com)
    * This notice must stay intact for use
    * Visit http://www.dynamicdrive.com/ for full source code
    ***********************************************/
    
    //1) CUSTOMIZE TEXT DESCRIPTIONS FOR LINKS ABOVE
    var thetext1=new Array()
    thetext1[0]="Comprehensive JavaScript tutorials and over 400+ free scripts"
    thetext1[1]="Direct link to hundreds of free Java applets online!"
    thetext1[2]="Up to date news on the technology front"
    thetext1[3]="News.com- The #1 technology News site."
    thetext1[4]="Web Coding and development forums"
    
    /// You may define additional text arrays if you have multiple drop downs:
    var thetext2=new Array()
    thetext2[0]="CNN- US and World News."
    thetext2[1]="MSNBC- NBC News online."
    thetext2[2]="BBC News- Updated every minute of every day."
    thetext2[3]="TheRegister- Daily IT news."
    
    // Now, see 2) below for final customization step
    
    function displaydesc(which, descriptionarray, container){
    if (document.getElementById)
    document.getElementById(container).innerHTML=descriptionarray[which.selectedIndex]
    }
    
    function jumptolink(what){
    var selectedopt=what.options[what.selectedIndex]
    if (document.getElementById && selectedopt.getAttribute("target")=="newwin"){
    if (selectedopt.className!="")
    window.open(selectedopt.value, "", "width="+parseInt(selectedopt.className.split("by")[0])+",height="+parseInt(selectedopt.className.split("by")[1]))
    else
    window.open(selectedopt.value)
    }
    else
    window.location=selectedopt.value
    }
    
    //2) Call function displaydesc() for each drop down menu you have on the page
    //   This function displays the initial description for the selected menu item
    //   displaydesc(name of select menu, name of corresponding text array, ID of SPAN container tag):
    //   Important: Remove the calls not in use (ie: 2nd line below if there's only 1 menu on your page)
    
    displaydesc(document.form1.select1, thetext1, 'textcontainer1')
    displaydesc(document.form2.select2, thetext2, 'textcontainer2')
    
    </script>

  3. #3
    Join Date
    Dec 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I tried using the Code and it indeed opens a New window, But it does not size the window accordingly.

    Any ideas of how I can get the window to size to my specifications?


    Thank you,

    Dave

Bookmarks

Posting Permissions

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