Form that results in a URL

  • Thread starter Christopher Grenness
  • Start date
C

Christopher Grenness

I'm sure there's an easy solution here, but I couldn't narrow down an
answer via Google (my search terms resulted in far to many hits).

Here's what I want:

A form with a one-line text box and a submit button.

When I enter "test" in the text box and hit Submit, I'm taken to the
URL http://xxxxxx.xxx/test

When I enter "anothertest" in the text box and hit Submit, I'm taken
to the URL http://xxxxxx.xxx/anothertest

The domain name never has to change, just the last part of the URL
should be changed based on what was entered via the form.

Can anyone help?

Best regards,

Christopher
 
N

Nik Coughin

Christopher said:
I'm sure there's an easy solution here, but I couldn't narrow down an
answer via Google (my search terms resulted in far to many hits).

Here's what I want:

A form with a one-line text box and a submit button.

When I enter "test" in the text box and hit Submit, I'm taken to the
URL http://xxxxxx.xxx/test

When I enter "anothertest" in the text box and hit Submit, I'm taken
to the URL http://xxxxxx.xxx/anothertest

The domain name never has to change, just the last part of the URL
should be changed based on what was entered via the form.

Can anyone help?

Best regards,

Christopher

You could use Javascript (although some people turn it off).

<input type="text" name="newLocation" size="20">
<input type="button" value="Go" name="btnGo"
onClick="location.replace('http://www.google.com/search?q='+document.getElem
entById('newLocation').value)">

You would replace the string http://www.google.com/search?q= with whatever
your URL is.
 
N

Nik Coughin

Nik said:
You could use Javascript (although some people turn it off).

<input type="text" name="newLocation" size="20">
<input type="button" value="Go" name="btnGo"
onClick="location.replace('http://www.google.com/search?q='+document.getElem
entById('newLocation').value)">

You would replace the string http://www.google.com/search?q= with
whatever your URL is.

You'd be much better off doing it server side however, say with PHP. Don't
think the above JS would work in Mozilla, for starters, or many other non-IE
browsers.
 
B

Bob Novell

Nik said:
Nik Coughin wrote:



You'd be much better off doing it server side however, say with PHP. Don't
think the above JS would work in Mozilla, for starters, or many other non-IE
browsers.
That Javascript should work in Netscape. Why would it not work in
Mozilla? Netscape 7.1 is based on Mozilla.

I'l make up a page quickly and see if it does, indeed, work in Netscape
7.1 -- be back in a few minutes.

Bob
 
N

Nik Coughin

That Javascript should work in Netscape. Why would it not work in Mozilla?
Netscape 7.1 is based on Mozilla.
I'l make up a page quickly and see if it does, indeed, work in Netscape
7.1 -- be back in a few minutes.

I said that it might not work, I didn't actually test it :) Maybe it works
just as well with Mozilla and friends. It will definitely work with IE, I
do stuff like that all the time on the intraweb at work.
 
B

Bob Novell

Nik said:
Netscape 7.1 is based on Mozilla.



7.1 -- be back in a few minutes.

I said that it might not work, I didn't actually test it :) Maybe it works
just as well with Mozilla and friends. It will definitely work with IE, I
do stuff like that all the time on the intraweb at work.

It works on I.E. 6, Netscape 4.8, and Netscape 7.1 - after fixing some
typos and changing the way you referenced the value of the input box,
and setting location.href instead of using location.replace

This is what I finally wound up with.

<form>
<input type="text" name="newLocation" size="20"><input type="button"
value="GO" name="btnGo"
onclick="window.location.href='http://www.google.com/search?q=' +
newLocation.value">
</form>

Put this in a page and browse it and then you can put words in the input
box and click the button and it take you to Google and search on the
words form the input box.

newLocation.value is an easier way to get the value of the input box.

Setting window.location.href is a more appropriate way to go to another
page rather than using the replace function.

If you use the replace function, it will replace the entry in the
history. If you simply set the value of location.href, it will be just
as though you'd click a normally coded link - there will be an entry in
the history for both the page with the form and the page to which it
takes you.

This code can easily be modified to create the href in some other format
like Christopher needed.

Bob

Bob
 
M

Mark Parnell

You'd be much better off doing it server side however, say with PHP. Don't
think the above JS would work in Mozilla, for starters, or many other non-IE
browsers.

Better off doing it server side anyway, because it won't do anything for
those with Javascript disabled/unavailable.
 
H

Hywel Jenkins

Nik Coughin said:
You'd be much better off doing it server side however, say with PHP. Don't
think the above JS would work in Mozilla, for starters, or many other non-IE
browsers.

It would, if it's coded properly. Your PHP suggestion is far better, though.
 
C

Christopher Grenness

You'd be much better off doing it server side however, say with PHP. Don't
Better off doing it server side anyway, because it won't do anything for
those with Javascript disabled/unavailable.

Thanks, guys.
This is actually supposed to work mainly on PDAs, so I guess JS
abilities are limited.
How do I do it server side?
Or is that way too complicated for a novice like myself?

Thanks again!

/Christopher
 
M

Mark Parnell

How do I do it server side?
Or is that way too complicated for a novice like myself?

You would need the server to support a server-side scripting language,
e.g. PHP, ASP, Perl, CGI, etc.

PHP is supposed to be very easy for a "novice" to pick up. What you want
wouldn't be particularly complicated. In fact, if you ask nicely,
someone might even bash something quick out for you. ;-)
 
J

Jeff Thies

Here's perl

#!/usr/bin/perl

use CGI;
my $query=new CGI;
my $page_path=$query->param('my_rolldown');

print $query->redirect($page_path);



the rolldown would look like this:

<select name="my_rolldown">
<option value="/some_path/some_page.html">page 1</option>

....

That's a bit too simple, but will work. PHP and other languages will also be
easy. That will work on almost any server and any web browser.

Jeff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top