Script that lets the client change the background color of my website..
I want to have a simple script like this...
They can pick from orange, blue, green etc, then submit it and it gives them a cookie so they always have that background setting!
Thanx in advance,
-Quickstrike
Denise posted this at 13:03 — 6th October 2000.
They have: 19 posts
Joined: Oct 2000
Hi,
I know this is a Perl Forum but I really think it would be much easier to do in Javacript.
Here's the code to place in your page
---------------------------------------------------
<script LANGUAGE="Javascript">
</script>
<script LANGUAGE="Javascript">
</script>
<script LANGUAGE="Javascript">
</script>
---------------------------------------------------
Here's the code to place where you're tag appears:
<script LANGUAGE="Javascript">
\n");}
else{
document.write("\n");}
//-->
</script>
----------------------------------------------------
And here's the link to place on your page!
Click here to choose your background color!
This all works, I tried it!
Regards,
Denise
[Edited by Denise on 10-06-2000 at 09:15 AM]
Ken Elliott posted this at 15:11 — 6th October 2000.
They have: 358 posts
Joined: Jun 1999
Wow..I really don't know JavaScript to well..but it doesn't look much easier.
Here is my code..
1st page: choose the color..
Blue
Red
Black
White
Script: shows color and page
#!/usr/bin/perl -w
&Parse;
$color = $formdata{'color'};
print "Content-type:text/html\n\n";
print "";
print "So you chose $color...nice choice";
print "";
sub Parse {
@pairs = split(/&/, $ENV{'QUERY_STRING'});
foreach $pair (@pairs) {
($key, $value) = split (/=/, $pair);
$key =~ tr/+/ /;
$key =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~s///g;
if ($formdata{$key}) {
$formdata{$key} .= ", $value";
} else {
$formdata{$key} = $value;
}
}
}
Hmm...well neither is very pretty to look at.
Pimpin like a pimp with an electrofied pimpin machine!
Denise posted this at 15:27 — 6th October 2000.
They have: 19 posts
Joined: Oct 2000
Hi,
The only reason I suggest Java is because it's a live language, really speeds things up here and doesn't rely on cgi.. and either way, even if you do include a cookie writing subroutine in your Perl example, you'd still have to use Java to retrieve it otherwise each page would have to be generated via cgi.
This can be difficult because the cgi would have to know exactly the content of each page to be displayed and then print it again, which means reading the data as an array and returning it to the browser.
I think Perl cgi would only be neccessary if you were constantly returning standard pages with many fields dependant on a surfer's chosen variables.
But what the heck, it's a free world!
Denise
Vincent Puglia posted this at 18:53 — 6th October 2000.
They have: 634 posts
Joined: Dec 1999
Hi Quickstrike,
I agree with Denise in that if you wish to save only a few variables, javascript cookies is the way to go. It's relatively simple to implement, requires no cgi access, and responds faster because it is client-side.
However, if you intend to save more than a few variables, I would recommend going the cgi route -- a database for storing the user selections, usernames, passwords, etc. Not everyone allows a cookie and cookies eventually expire or get overwritten by someone else's cookie.
Ken: I agree. Both code snippets look like some sort of magical incantation (especially the perl one, since I have very little background in it
Vinny
Where the world once stood
the blades of grass cut me still
fairhousing posted this at 05:27 — 7th October 2000.
They have: 1,587 posts
Joined: Mar 1999
i'd go with the javascript, it's more efficient for the task at hand.
Suzanne posted this at 02:37 — 18th October 2000.
She has: 5,507 posts
Joined: Feb 2000
Two things about this, just nit picking.
1. Java is NOT the same as JavaScript. Not even close. They are two totally different languages with similarities, but they are not the same thing.
2. You don't have to generate a whole page to use CGI. You can include or execute CGI files within a regular page (with server side includes turned on). Of course, generating a page from a template rather than hard-coding it also saves time in the future, but that's a different discussion.
Suzanne
mjames posted this at 20:36 — 18th October 2000.
They have: 2,064 posts
Joined: Dec 1999
Yeah, but users with JavaScript disabled won't be able to use it...
Mark Hensler posted this at 06:09 — 19th October 2000.
He has: 4,048 posts
Joined: Aug 2000
Suzanne-
right on!
I'd go with the cgi (or perhaps PHP ) executed (or include for PHP) to set the vars...
unless I'm missing something, Ken's code won't work for return visits (without caching on).
if you use cgi/php, you could have the a DB store the preferences and access it with the users IP, or a single cookie with a unique user id. OR you could just set cookies holding all the vars you need (there is a limit)
Mark Hensler
If there is no answer on Google, then there is no question.
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.