Results 1 to 2 of 2

Thread: "custom location bar"

  1. #1
    Join Date
    Jan 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default "custom location bar"

    I'm trying to get a variation of the CUSTOM LOCATION BAR on http://www.sivamdesign.com/scripts/navigate.html (code can be found at http://www.sivamdesign.com/scripts/dwld/location.txt )to work.

    Basically, I want to have users enter a string (e.g., 1234) into a text box, click on the GO button, and then be taken to
    http://domain.com/page.php?1234

    Is that possible, and if so, how is it done?

    Any help is greatly appreciated!

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Here you go:
    HTML Code:
    <script type="text/javascript">
    var locateTo = function(els){
      window.location.href = "page.php?"+els.elements['locate'].value;
    };
    </script>
    <form action="page.php" method="get" onsubmit="locateTo(this); return false; ">
    <input type="text" name="locate"/><input type="submit" />
    </form>
    You should also make this compatible with javascript disabled users. To do this, on page.php, add:
    PHP Code:
    <?php
      
    if(isset($_GET['locate'])) {
        
    header("Location: ".$_SERVER['PHP_SELF']."?".$_GET['locate']);
      }
    ?>
    Of course - if you do that then all you need to do with the <form> I gave you 2 codes above is:
    HTML Code:
    <form action="page.php" method="get">
    <input type="text" name="locate"/><input type="submit" />
    </form>
    Which I highly suggest.
    Jeremy | jfein.net

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
  •