Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Design Is there a way to navigate to a url from an input?

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #275014
    Zander
    Participant

    What I need to do is this:

    The user shall type in a number in an input field, hit „enter“ and shall navigate to a page with that number in the url, like with an id.

    Something like „pagename.html#203“.

    How would I do that?

    #275025
    Shikkediel
    Participant

    This would be one way :

    codepen.io/anon/pen/EppYWY

    document.getElementsByTagName('input')[0].addEventListener('keyup', function(e) {
    
      if (e.key == 'Enter') location.href = 'pagename.html#' + this.value;
    });
    
    #275035
    Zander
    Participant

    Thank you very much!

    At first it wouldn’t work here. Only after I removed the form element. Very strange.

    After some heavy googeling with the right search terms, that I was now able to guess by your code, I added a button to the mix.

    Cool!

Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘Design’ is closed to new topics and replies.