View Full Version : Simple javascript redirect button

05-24-2012, 03:30 PM
Hello. I have searched for a solution to this (google and this forum) but I havent found a satisfactory answer. I know that this is probably very simple, but I really would appreciate some help.

To outline. I have a page on www.example.com
On that page I need to have a textbox, and a submit button. When the button is clicked, I need the page to redirect to www.example.com/"textboxvalue".

So if for example "Customer1" is entered into the textbox, I would like the button to load the page http://www.example.com/customer1

I'd be really greatful if someone could point me in the right direction for this.
Many thanks in advance :)

05-24-2012, 03:52 PM
This sounds like a homework exercise, but the basic steps are:

1. attach an onclick event handler to the button.

2. when the button is clicked, the event handler gets the value from the textbox using getElementById() to access the textbox object in the DOM.

3. Then get the user input from the value attribute of the textbox object and append it to the base url you have.

4. Then use window.location.href to redirect to the url in 3.

Hiya iBall thanks for the quick reply. I can assure you this isn't homework (I'm 26) this is for my partner's website. At the moment customers have to manually type the address of their details page.

I thought that being able to enter their username in a login style box would add a touch of professionalism.

Thanks again for the help though. I shall give it another go and see what I can do :)

low tech
05-24-2012, 03:54 PM

This might get you going

see post2



05-24-2012, 04:05 PM
Thank you both so much for your help. This is exactly what I'm looking for :thumbsup: