OT Drop Down Scripts

D

Davmagic .Com

I am currently using JavaScript to run my Drop Downs, and would like to
change to a CGI Script, maybe Perl...

Where can I find a simple and secure Perl script to do this?

Web Design, Magic, Painting, Junking, More
http://www.davmagic.com
Paint A House
http://www.paintahouse.com
NOTE: This emailbox is CLOSED do NOT reply!!!
 
T

Tina - AffordableHOST, Inc.

Davmagic .Com said:
I am currently using JavaScript to run my Drop Downs, and would like to
change to a CGI Script, maybe Perl...

Where can I find a simple and secure Perl script to do this?


cgi-resources.com used to have a bunch of good ones. I haven't been there
lately though.

--Tina
 
H

Hywel

Davmagic said:
I am currently using JavaScript to run my Drop Downs, and would like to
change to a CGI Script, maybe Perl...

Where can I find a simple and secure Perl script to do this?

http://cgi.resourceindex.com/ - if you can't find a ready-written script
to do it you'll certainly find a CGI library that will take care of
getting at the form data.
 
D

David Dorward

Davmagic said:
I looked at cgi resources and couldn't find what I want... no script to
process drop downs...

I find that hard to believe ... but I hacked this together in a couple of
minutes. I suggest you learn Perl, it isn't difficult:

(Changes should be obvious. Name your select element "link".)

#!/usr/bin/perl

use strict;
use warnings;
use CGI;

my $site_root = 'http://www.example.com/thing/';

my %pages = (
home => '',
away => 'away/',
far_far_away => 'away/run.html'
);

my $location = $site_root . '/'; # Default

my $cgi = new CGI;

$location = $site_root . $pages{$cgi->param('link')}
if (
defined $cgi->param('link') &&
defined $pages{$cgi->param('link')}
);

print <<EOF;
Location: $location
Content-Type: text/html; charset=iso-8859-1

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<title>Document Found!</title>
<h1>Document Found!</h1>
<p>The document you were looking for can be found at
<a href="$location">$location</a>.</p>
EOF
 
H

Hywel

Davmagic said:
I looked at cgi resources and couldn't find what I want... no script to
process drop downs... any other suggestions? And since I don't write
script...

Learn to write script. It's easier with PHP, so perhaps starting at
http://www.php.net/ would be good.
 
D

David Dorward

aa said:
I don't. English ain't my mother tonge
What are Drop Dawns in this context?

In this context ... you are still misspelling them. See the subject for the
correct spelling.

A "Drop Down" is, I suspect, referring to a <select> element since they are
commonly rendered as what, in most GUI toolkits, are referred to as Drop
Down Menus.
 
J

Jeffrey Silverman

I am currently using JavaScript to run my Drop Downs, and would like to
change to a CGI Script, maybe Perl...

What do you mean, "run your drop downs"?
 
D

Davmagic .Com

From: (e-mail address removed)
(Jeffrey Silverman)

What do you mean, "run your drop
downs"?

JavaScript processes the drop down select element.... causing the
browser to goto the chosen option value.... source my front page to see
the code for the drop down on it... as an example

I want to use a Perl CGI Script to eliminate the 11% (or so) who have JS
disabled on their browsers...

...but can't seem to find a readily available script, that will work
just like the JS that I use now... ie goes to the page when the select
option is clicked, without having a "Go" button to press... and goes
_directly_ to the page, without having the script return a page with a
link on it, to be clicked to goto the desired page (as David Dorward's
script proposal suggests)...

Web Design, Magic, Painting, Junking, More
http://www.davmagic.com
Paint A House
http://www.paintahouse.com
NOTE: This emailbox is CLOSED do NOT reply!!!
 
T

Toby Inkster

Davmagic said:
I want to use a Perl CGI Script to eliminate the 11% (or so) who have JS
disabled on their browsers...

If I were you, I'd use a combination Javascript and PHP solution. This
will use Javascript for those who can, and fall back to PHP for the rest:

In your <head>:

<script type="text/javascript">
function redirect() {
var sel = document.getElementById("r");
var sid = sel.selectedIndex;
var page = sel.options[sid].value;
window.location.href = page;
return false;
}
</script>

In your <body>:

<form action="/redirect.php" method="GET" onsubmit="redirect();">
<div>
<select id="r" name="r">
<option value="/index.html">Home</option>
<option value="/contact.html">Contact Me</option>
<option value="/blah.html">Blah</option>
</select>
</div>
</form>

And here is redirect.php, which should be put into your document root:

<?php
$page = $_GET['r']
header('HTTP/1.1 302 Found');
header("Location: $page");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<title>HTTP/1.1 302 Found</title>
<h1>HTTP/1.1 302 Found</h1>
<p>The document you were looking for can be found at
<a href="<?= $page ?>"><?= $page ?></a>.</p>

and that's it. More efficient that a straight server-side redirect.
 
T

Toby Inkster

Toby said:
<form action="/redirect.php" method="GET" onsubmit="redirect();">
<div>
<select id="r" name="r">
<option value="/index.html">Home</option>
<option value="/contact.html">Contact Me</option>
<option value="/blah.html">Blah</option>
</select>
</div>
</form>

Argh! You're going to want a submit button in there somewhere too!
 
D

Davmagic .Com

From: (e-mail address removed)
(Toby Inkster)
If I were you, I'd use a combination
Javascript and PHP solution. This will use
Javascript for those who can, and fall
back to PHP for the rest:
<snip code>

Thanks, but it doesn't seem to work... I copied all your code,
implimented it as you indicated, but get an ERROR "File not found" when
hitting the submit button!

Again I don't need a submit button with the current JS script that I now
use... and would like to "keep it that way" with any other scripts that
I convert to...

But your code doesn't seem to work as you explained anyway, I had JS
enabled, but it used the form action and used the php script anyway...
did not use the JS? Still did get the ERROR...

Web Design, Magic, Painting, Junking, More
http://www.davmagic.com
Paint A House
http://www.paintahouse.com
NOTE: This emailbox is CLOSED do NOT reply!!!
 
T

Toby Inkster

Davmagic said:
Thanks, but it doesn't seem to work... I copied all your code,
implimented it as you indicated, but get an ERROR "File not found" when
hitting the submit button!

Let's have a look. URL?
Again I don't need a submit button with the current JS script that I now
use... and would like to "keep it that way" with any other scripts that
I convert to...

Well, you can't. Tough. Without a submit button, how can people submit the
form?
 
D

Davmagic .Com

From: (e-mail address removed)
(Toby Inkster)
Let's have a look. URL?
http://davmagic.com/testindex.html

Well, you can't. Tough. Without a submit
button, how can people submit the form?

The JS that I am using now, uses the "onchange" event for the select tag
to submit the form, here's the URL: http://davmagic.com/index.html

Why can't this be done with another non-JS script?

Web Design, Magic, Painting, Junking, More
http://www.davmagic.com
Paint A House
http://www.paintahouse.com
NOTE: This emailbox is CLOSED do NOT reply!!!
 
S

Steve Pugh

Thanks, but it doesn't seem to work... I copied all your code,
implimented it as you indicated, but get an ERROR "File not found" when
hitting the submit button!

First thing to check: does your server support PHP?
Again I don't need a submit button with the current JS script that I now
use... and would like to "keep it that way" with any other scripts that
I convert to...

Not possible. The form must be submitted to the serve in order for a
server side script to handle it. This requires either JavaScript
(pointless if the server side script is a fallback for when JS is
disabled) or a submit button.

Steve
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top