#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Posts
    6
    Rep Power
    0

    go to an anchor via a combo box with Javascript


    I am trying to get a combo box full of names and when the user selects one it automatically goes to that anchor on the page without the page refreshing.

    I can create the combo box no problems but I need help with the Javascript.

    Thanks in advance.
  2. #2
  3. mod_dev_shed
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2002
    Location
    Atlanta, GA
    Posts
    14,817
    Rep Power
    1100
    Code:
    <form>
    <select onchange="javascript:window.location=window.location+this.options[this.selectedIndex].value">
      <option value="#anchor1"> Anchor 1</option>
      <option value="#anchor2"> Anchor 2</option>
    </selected>
    </form>
    Never done it. Didn't test the code. Netscape will probably refresh anyway (I believe that's a property of Netscape).
    # Jeremy

    Explain your problem instead of asking how to do what you decided was the solution.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Posts
    6
    Rep Power
    0
    Thanks for the quick reply. It works great the first time I change the value in the combo box but if I scoll back to the top and choose another name it doesn't go down to that anchor.

    I'm using IE 6.0 and the page doesn't refreh.
  6. #4
  7. mod_dev_shed
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2002
    Location
    Atlanta, GA
    Posts
    14,817
    Rep Power
    1100
    Ah yes, I would assume that's b/c window.location includes the anchor so you end up with http://domain.com/page.html#anchor1#anchor2. Try instead:
    Code:
    <form>
    <select onchange="java script:window.location.hash=this.options[this.selectedIndex].value">
      <option value="anchor1"> Anchor 1</option>
      <option value="anchor2"> Anchor 2</option>
    </selected>
    </form>
    # Jeremy

    Explain your problem instead of asking how to do what you decided was the solution.
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Posts
    6
    Rep Power
    0
    Thankyou so much! It works great.

IMN logo majestic logo threadwatch logo seochat tools logo