SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Jan 2007
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    dropdown menu - go button not working

    Hello all,

    I'm trying to use the following script (which I didn't write) to create a dropdown list. When the 'go' button is pressed it will jump to the appropriate url:

    Code:
    <form name="htmlMenu">
      <select name="htmlSelList" size="1">
        <option selected value="#">Select a page, then Go!
        <option value="http://www.lycos.com">lycos</option>
        <option value="http://www.google.com">google</option>
        <option value="http://www.yahoo.com">yahoo</option>
        <option value="http://www.cnet.com">cnet</option>
        <option value="http://www.bnet.com">bnet</option>
      </select>
      <input type="button" onClick="document.location = document.htmlMenu.htmlSelList.options [document.htmlMenu.htmlSelList.selectedIndex].value;"
     value="GO">
    </form>
    this all works fine. My problem is that instead of the standard submit button, I tried using the following code so as to use an image for the 'go' button:

    Code:
    <input type="image" src="_images/goButton.gif" border="0" onClick="document.location = document.htmlMenu.htmlSelList.options [document.htmlMenu.htmlSelList.selectedIndex].value;" />
    Using this line of code does not work? Any help as to why?

    Thanks very much in advance!

  2. #2
    SitePoint Wizard chris_fuel's Avatar
    Join Date
    May 2006
    Location
    Ventura, CA
    Posts
    2,750
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try latching on a "return false;" at the end of the onClick code. This should prevent the form from submitting. If nothing else, you can use css to make a button type look like an image type by a blank value and "background-image: url(_images/goButton.gif);" for the style. Hope that helps.

  3. #3
    SitePoint Member
    Join Date
    Jan 2007
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Chris, thanks!

    The 'return false' worked. What exactly does that do?

  4. #4
    SitePoint Wizard chris_fuel's Avatar
    Join Date
    May 2006
    Location
    Ventura, CA
    Posts
    2,750
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's there to stop the form from submitting. Image button submit the form with a post with this information:

    imageFieldName_x imageFieldNameY (and other post values iirc)

    so return false prevents it from doing this post.

  5. #5
    SitePoint Member
    Join Date
    Jan 2007
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Great. Thanks again!


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
  •