SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: link cut-up

  1. #1
    SitePoint Member
    Join Date
    Dec 2005
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    link cut-up

    Hey guys.
    This is my first time on the forum.

    Got a simple thing to be done, but my Javascript knowledge is c.r.a.p.

    I want an input-field with a submit button.
    If you put "sam" in the input-field and you press enter or the button, a new window with http://www.sam.com/ will open.

    To be straight:
    I want to paste a string into an URL.


    Thanks in advance.
    Sam
    Last edited by Sammieman; Dec 15, 2005 at 09:16. Reason: spelling

  2. #2
    SitePoint Evangelist SpaceFrog's Avatar
    Join Date
    Jan 2005
    Location
    Outerspace
    Posts
    511
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you would juste need to add a test to avoid empty text ...
    or add a try / catch to avoid error 404
    PHP Code:
    <script type='text/javascript'>
    function 
    letsgo(){
        
    window.location.replace("http://www."+document.getElementById('where').value+".com")
        }
    </script>

    </head>

    <body>
    <input type="text" id="where" />
    <input type="button" onclick="letsgo()" value="let's go"/>
    </body>
    </html> 

  3. #3
    SitePoint Evangelist SpaceFrog's Avatar
    Join Date
    Jan 2005
    Location
    Outerspace
    Posts
    511
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oups I skipped new window...
    PHP Code:
    <script type='text/javascript'>
    function 
    letsgo(){
        
    window.open("http://www."+document.getElementById('where').value+".com")
        }
    </script> 

  4. #4
    SitePoint Member
    Join Date
    Dec 2005
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Perfect,
    just what I needed.
    Thanks a lot!

    Sam

  5. #5
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,789
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    You need to put your form fields into a form as well or it will fail on some browsers.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  6. #6
    SitePoint Evangelist SpaceFrog's Avatar
    Join Date
    Jan 2005
    Location
    Outerspace
    Posts
    511
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    why should it fail in some browsers... you may have some w3c validating problems but it should run whatever browser you use ???

  7. #7
    SitePoint Member
    Join Date
    Dec 2005
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Uhm,
    should I do it or not.
    What's best???

  8. #8
    SitePoint Evangelist SpaceFrog's Avatar
    Join Date
    Jan 2005
    Location
    Outerspace
    Posts
    511
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you can just put a couple of form tags around it won't hurt ...


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
  •