Click to See Complete Forum and Search --> : navigation script?


rbottner
08-16-2003, 11:04 AM
I am looking very hard for a script to do the following, but I can't find one.

I want a script that would generate a small text field. The user would type in a number and then click submit. The script would then redirect the user to a specific page. It would work as follows:

Webpage is on server: http://www.xyz.com/server/

User types in 453 into text and then clicks SUBMIT.

User is transferred to: http://www.xyz.com/server/453.htm

In other words, all users are transferred to http://www.xyz.com/server/XXXXX.htm where the XXXXX is the number they type in the text field.

Can this be done? If so, HOW!?!?!?

THANK YOU!!!

Khalid Ali
08-16-2003, 11:14 AM
very easy...

just make sure tha relative pages are present at server.
Suppose the text fuields name is url field

<input type="text" name="urlField"/>
<input type="button" onclick="window.location.href = this.form.urlField.value;"/>

should help you..

rbottner
08-16-2003, 11:21 AM
could you put that into lamens terms please? I am not a complete newbie.. ive been working with HTML for years, just scripting like this always confuses me. Thank you!

Khalid Ali
08-16-2003, 11:52 AM
it could not get any simpler then that..just add the above in between the <form tags just as you would add 2 inputs one text field and the other button.then enter the url in the text field and clik the button..

rbottner
08-16-2003, 12:34 PM
But how does the script know to transfer the person to a XXXX.htm? Where am I telling it that?

Charles
08-16-2003, 12:46 PM
You have a couple of ways to do that in JavaScript but it's very bad to use JavaScript for navigation. If your form looks something like:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<form action="cgi-bin/go.pl">
<div>
<input type="text" name="number">
<button type="submit">Go</button>
</div>
</form>

Then get something like the following Perl script up and running on your server and named "go.pl":

#!user/local/bin/perl
use CGI qw(header redirect param);
print header, redirect 'http://www.xyz.com/server/'.(param 'number').'.htm';

rbottner
08-22-2003, 10:57 PM
I'd like to try the PERL route. I've never worked with PERL before. I have the form part of the script working - but I get a server 500 error. Can someone explain to me exactly what I should do with the perl part of this? (the go.pl) file. Thank you!

rbottner
08-23-2003, 11:26 AM
btt

Jupac
08-23-2003, 11:31 AM
do u have a cgi-bin??

Charles
08-23-2003, 12:54 PM
Using JavaScript for navigation is very bad. So bad that it is against the law in some places for some web sites.

To get the Perl script running you will need to talk to your server people.

AdamBrill
08-23-2003, 02:14 PM
Originally posted by Charles
So bad that it is against the law in some places for some web sites. This should be reworded to this:

"So bad that it is against the law in very few places for very few web sites."

You are right that it shouldn't be done in JS, but you probably didn't have to make it a legal thing... ;)

Anyway, you need to upload go.pl to your cgi-bin and chmod it to have executive rights(and your server has to support Perl)... Also, you have to make sure this line is correct:

#!user/local/bin/perl

Most of the time it is this:

#!usr/bin/perl

Does your server support PHP? If so, it would be MUCH easier with that... Let me know if it does and I'll get you a script.

rbottner
08-23-2003, 04:46 PM
It does not support PHP but the PERL stuff is located in the "CGI-BIN" directory. How do I change that top line of the script? Thanks!

AdamBrill
08-23-2003, 04:56 PM
Well, if the line is #!usr/bin/perl, you would just change the content of the file to:

#!usr/bin/perl
use CGI qw(header redirect param);
print header, redirect 'http://www.xyz.com/server/'.(param 'number').'.htm';

If it doesn't work like that, you will have to contact your host to see what the correct line is...

rbottner
08-30-2003, 10:58 PM
<input type="text" name="urlField"/>
<input type="button" onclick="window.location.href = this.form.urlField.value;"/>




That transferred the user to www.richap.com/023


How do I add the ".htm" to that? Thanks!

rbottner
08-31-2003, 07:54 AM
btt

AdamBrill
09-01-2003, 09:40 PM
You would do it like this:

<input type="text" name="urlField"/>
<input type="button" onclick="window.location.href = this.form.urlField.value+'.htm';"/>

But that is highly recommended against, since it will fail for all non-JavaScript users. You would be best to try to get the CGI working.