View Full Version : Using a form to generate a URL

Aug 29th, 2007, 10:51 AM
I simply can't get my head around this, I want to use a simple for to generate a URL ... as a basic example:

The user would input "andrew" in a form.

A resulting web page would show a clickable URL (example: "www.mydomain.com/andrew")

I need to work some validation around which "mydomain" URL to use but I can easily sort that, I am just stuck on this process of generating the basic URL!

Simple HTML Form or Javascript ... happy to accept either.

Thanks in advance.

Aug 29th, 2007, 11:10 AM
I think you could probably do this with javascript quite easily? Make sure you give the form a name and then call the value of that field onsubmit into a variable called something like 'username'.

With a form like:

<form id="userform" method="get" action="">
<input name="username" value="Insert Username" type="text" />
<input type="submit" value="Submit" />

You could call the value of 'username' via:

var theUser = document.getElementById('userform').username.value;
url = url + '/' + theUser;

This would alert a popup box with the correct URL. That is about the sum of my javascript knowledge. Stick that little bit of js in a function and call it onsubmit in the form and then use something like document.write to print the outcome to the page?

I'm sure someone with a little more knowledge will be able to help you further, but that's where I'd start?

Aug 29th, 2007, 02:18 PM
Thanks for that - I changed the way I work it (from an alert box to a new page) - but you were a great help.

Aug 29th, 2007, 02:37 PM
Not a problem... the alert box was just there to show you the URL that would appear anyways :)