Go Back   CodingForums.com > :: Server side development > Perl/ CGI

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-24-2002, 08:08 PM   PM User | #1
The_Dude1
New to the CF scene

 
Join Date: Sep 2002
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
The_Dude1 is an unknown quantity at this point
Perl Value Variable

Hi,

Wondering if anyone can point me in the correct direction. I have a Variable which is either 1 or 2. If the user selects 1. Then loads the next page. I want it to display certain txt different than if they choose 2. (using cgi Script)

In batch file it would be something like.

if exist 1 echo Hello 1
if exist 2 echo Hello 2.

I know its not the same, but may help in explaining what I am tring to do.

Any Ideas would be greatful as this is a show stopper at the moment.
The_Dude1 is offline   Reply With Quote
Old 09-25-2002, 08:49 AM   PM User | #2
fivesidecube
New Coder

 
Join Date: Sep 2002
Location: Up North (UK)
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
fivesidecube is an unknown quantity at this point
The_Dude1,

Have a look at the thread here. In the beginning it, the requester was doing comparisons by numerical value (which is what you are asking to do) when they needed a comparison by string.

Their initial example code demonstrates exactly what you are asking for.

Hope this helps.
fivesidecube is offline   Reply With Quote
Old 09-25-2002, 07:45 PM   PM User | #3
The_Dude1
New to the CF scene

 
Join Date: Sep 2002
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
The_Dude1 is an unknown quantity at this point
mm no luck.

I`ll try and explain a little more what I want.

page 1 a user selects an option (i.e food)
That then goes as a hidden name food

Page 2

if user selected food then display this:- So you want food.
The_Dude1 is offline   Reply With Quote
Old 09-25-2002, 08:28 PM   PM User | #4
fivesidecube
New Coder

 
Join Date: Sep 2002
Location: Up North (UK)
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
fivesidecube is an unknown quantity at this point
The_Dude1,

I don't really understand what you mean, but the code required to compare a varible against a value:
Code:
$Var = 1;

if( $Var == 1 )
{
	print "Var is one\n";
}
elsif( $Var == 2 )
{
	print "Var is two\n";
}
else
{
	print "Var is not one or two\n";
}
If you need more help, then I thing that an example is in order or posting your existing code.
fivesidecube is offline   Reply With Quote
Old 09-26-2002, 08:25 PM   PM User | #5
The_Dude1
New to the CF scene

 
Join Date: Sep 2002
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
The_Dude1 is an unknown quantity at this point
No Luck I get the following displayed on the web site.

= 1; if( == 1 ) { print "Var is one "; } elsif( == 2 ) { print "Var is two "; } else { print "Var is not one or two "; }


The Code is very long to post (part of a shopping cart).
I have the following:-

<INPUT TYPE=HIDDEN NAME=PAYME VALUE="NoChex">

or (depending on what option the user uses)

<INPUT TYPE=HIDDEN NAME=PAYME VALUE="Cheque">

Therefore I would like the page to display if the Value=Nochex
Click here to be redirected to Nochex

If the value is Cheque.
I would like the page to display.

Details will be emailed to you.


Hope that makes it a bit clearer.
If you can help it would be great.
The_Dude1 is offline   Reply With Quote
Old 09-27-2002, 01:11 PM   PM User | #6
fivesidecube
New Coder

 
Join Date: Sep 2002
Location: Up North (UK)
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
fivesidecube is an unknown quantity at this point
The_Dude1,

To demonstrate this working, I have created the following PERL script:
Code:
#!c:/perl/bin/Perl.exe

use CGI qw(:standard);

print "Content-type: text/html\n\n";

$PayMethod = param('PAYME');
print <<EOF;
<html><head><title>Test</title></head>
<body><select name="Method"	onchange="window.location=('/cgi-bin/select.pl?PAYME='+this.options[this.selectedIndex].value)">
		<option value="Other" >Other</option>
        <option value="NoChex" >NoChex</option>
		<option value="Cheque">Cheque</option>
</select>
EOF

if( $PayMethod eq "NoChex" )
{
	print "NoChex method of payment was selected\<BR\>\n";
}
elsif( $PayMethod eq "Cheque" )
{
	print "Cheque mehtod of payment was selected\<BR\>\n";
}

print <<EOF;
</body>
EOF
Try copying this sciprt into a file called select.pl in your cgi-bin directory. You may need to change the initial line to the correct path for your installation of PERL.

Initially the script provides you with a base page, when the drop down lick is changed, the script is recalled passing the PAYME parameter back. The value of PAYME is checked and the message is switched. There is no reason why this message should be a whole HTML page or a browser redirect message. Other processing, like the sending of an EMail can also be done.

I hope this helps.
fivesidecube is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:48 AM.


Advertisement
Log in to turn off these ads.