views:

24

answers:

2

Hi,

I'd like to create a very simple form which has one field where you can enter a 5 digit number - e.g. 12345. When you submit the form, I'd like the page to redirect to http://www.website.com/12345

I'm sure it must be fairly simple, but I've not been able to find the answer anywhere!

Very grateful for any help.

Thanks,

Andrew

+2  A: 

There are several things that could be prettier than this (such as extracting it to a function of its own, say) but this is in essence what you want to do.

<form onSubmit=" location.href = 'http://www.website.com/' + document.getElementById('idOfTheTextField').value; return false; ">
David Hedlund
That's brilliant David. Thanks a lot - that was exactly what I wanted and it works perfectly.
Amshowman
A: 

If people have JavaScript turned off then this wont work, so really you want something like this:

In PHP -

<?php 

$number=$_GET['number'];

header("Location: http://www.yoursite.com/$number");

?>

And your input field should look something like this with 'number' as the name:

<input name="number" value=""/>
Tim
Thanks Tim - it's for an intranet so Javascript won't be an issue.
Amshowman