Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    May 2012
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question How to take data entered into a textbox and place it into the URL?

    Hello!

    First off, please excuse my ignorance. I am a bit new to the coding world.

    I want users to be able to enter data into a textbox on my site, and the data then be placed at the end of a specific url, followed by '.html'.

    For example, say my website is mysite.com. If someone enters in the word "John" in the textbox and clicks the 'Submit' button, the URL should now be: mysite.com/John.html

    Thanks in advance!

  • #2
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,077
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Lightbulb

    Might want to keep in mind that you are at the accuracy of the typist to get to the correct site.
    Code:
    <html>
    <head>
    <title> Untitled </title>
    <script type="text/javascript">
    function gotoSite() {
      var where = document.getElementById('tURL').value;
    //  document.location.href = 'http://mysite.com/'+where+'.html';
    // uncomment line above and remove line below after testing
      alert('http://mysite.com/'+where+'.html');
    }
    </script>
    
    </head>
    <body>
    <input type="text" id="tURL" value="">
    <button onclick="gotoSite()">Go</button>
    </body>
    </html>
    Follow the directions above after testing to get to the site desired.

  • The Following 2 Users Say Thank You to jmrker For This Useful Post:

    AnAngryTree (05-22-2012), low tech (05-24-2012)

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,922
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    It may be worth noting that this is a relatively secure way of protecting access to a site, if "John" is the password and mysite.com/John.html
    the protected page. The password is not displayed in the text of the script.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #4
    New to the CF scene
    Join Date
    May 2012
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks jmrker!

    @Philip M
    That's exactly what I was going for! I didn't want to protect every page using .htaccess, so I decided to make pages with a random 6-10 character long name. Then use that name as a code to give to people.

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,922
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Quote Originally Posted by AnAngryTree View Post
    Thanks jmrker!

    @Philip M
    That's exactly what I was going for! I didn't want to protect every page using .htaccess, so I decided to make pages with a random 6-10 character long name. Then use that name as a code to give to people.
    Passwords made of of random characters are desperately hard to remember and esy to mistype .You might like to consider this script which generates words of alternate consonants and vowels, and are thus pronounceable (such as hobofuku or pegajodo). That is sufficiently secure for your purposes.

    Code:
    <script type = "text/javascript">
    
    var letters1="bcdfghjklmnpqrstvwxyz"
    var letters2 = "aeiou";
    var temp='';
    
    function generatepass(plength){
    temp = '';
    for (i=0; i<plength/2; i++) {
    temp+=letters1.charAt(Math.floor(Math.random()*letters1.length));
    temp+=letters2.charAt(Math.floor(Math.random()*letters2.length));
    }
    temp = temp.substring(0,plength);
    return temp;
    }
    
    function populateform(enterlength){
    document.pgenerate.output.value=generatepass(enterlength);
    }
    
    </script>
    
    <form name="pgenerate">
    <input type="text" size=18 name="output">
    <input type="button" value="Generate Password" onClick="populateform(this.form.thelength.value)"><br>
    <b>Password Length:</b> <input type="text" name="thelength" size=3 value="8">
    </form>

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •