...

View Full Version : How to take data entered into a textbox and place it into the URL?



AnAngryTree
05-22-2012, 03:24 AM
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!

jmrker
05-22-2012, 04:37 AM
Might want to keep in mind that you are at the accuracy of the typist to get to the correct site.


<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.

Philip M
05-22-2012, 07:49 AM
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.

AnAngryTree
05-22-2012, 10:46 PM
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.

Philip M
05-23-2012, 07:59 AM
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.



<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>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum