Results 1 to 7 of 7

Thread: Drop Down Menu w/ Description

  1. #1
    Join Date
    Jul 2005
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Drop Down Menu w/ Description

    How can I select the menu item and have it run without having to click a Go or Submit button? I want to avoid the extra step and I don't have room for the button.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Give the select element an onchange attribute. Set it equal to the onclick event:

    <select onchange="whatever the onclick for the button equaled">
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Jul 2005
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default DropDown Menu

    Sorry, I should have given you the link or the code. This is the form and select part, which is already using onChange to dropdown the menu options.

    <form name="form1">
    <select name="select1" size="1" style="font: 11px arial; padding-left: 6px; background-color:#FFFFFF" onChange="displaydesc(document.form1.select1, thetext1, 'textcontainer1')">

    Should I add an onClick?
    <select onchange="whatever the onclick for the button equaled">

    <option selected value="-1" class="text11">Quick Links</option>

    link to original
    http://www.dynamicdrive.com/dynamici...bodescribe.htm

    Thanks.

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    OK, from the demo, change this:
    Code:
    <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">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>
    to this:
    Code:
    <form name="form1">
    <select name="select1" size="1" style="background-color:#FFFFD7" 
    onChange="displaydesc(document.form1.select1, thetext1, 'textcontainer1');jumptolink(document.form1.select1)">
    <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">News.com</option>
    <option value="http://www.codingforums.com" target="newwin">Coding Forums</option>
    </select>
    <br>
    <!-- Button Removed & you may remove this too -->
    <span id="textcontainer1" align="left" style="font:italic 13px Arial">
    </span>
    </form>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Jul 2005
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Bravo!
    Thank you.

  6. #6
    Join Date
    Jul 2005
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    One more thing, I tried removing <span id="textcontainer1" align="left" style="font:italic 13px Arial"> because I don't need it but that leaves me with an error then the links don't work. Does something in the script need to change to remove that?

  7. #7
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    If you are going to go that 'bare bones', you need to remove:
    Code:
    displaydesc(document.form1.select1, thetext1, 'textcontainer1');
    from the onChange event so now it will look like this:
    Code:
    onChange="jumptolink(document.form1.select1)"
    and take these lines out of the script:
    Code:
    //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')
    At that rate there are other things you can remove from the script itself but, this is all that needs to be done to avoid the error. If you want to strip down the script though, all this may be removed (from the demo):

    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]
    }
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

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
  •