Web Analytics Made Easy -
StatCounter Onchange go to url - CodingForum

Announcement

Collapse
No announcement yet.

Onchange go to url

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Onchange go to url

    I know this is simple, but I can't find any script that seem to be the one that I need.

    So you have a simple select form.

    Code:
    <select name="goToUrl" onchange="goToUrl();"><option value="1">Page 1</option><option value="2">Page 2</option></select>
    And all I want is for it to get the value you and use that value you there for the page. The url would be something like this. http://example.com/index.php?page=1

    The only thing the select form would be doing is changing the url page= to equal to the value...

    What would be the JavaScript code for this?

  • #2
    Code:
    <select name="goToUrl" 
     onchange="location.href='http://example.com/index.php?page=' + this.options[this.selectedIndex].value;">
    <option value="">--choose--</option>
    <option value="1">Page 1</option>
    <option value="2">Page 2</option>
    ...
    </select>
    You *must* have a "dummy" first option, because onchange will only activate if the user changes from the existing display to another <option>. Without a dummy, there is no way for the user to ever select the first real choice.
    Be yourself. No one else is as qualified.

    Comment

    Working...
    X