Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Sep 2002
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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.

  • #2
    New Coder
    Join Date
    Sep 2002
    Location
    Up North (UK)
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #3
    New to the CF scene
    Join Date
    Sep 2002
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #4
    New Coder
    Join Date
    Sep 2002
    Location
    Up North (UK)
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #5
    New to the CF scene
    Join Date
    Sep 2002
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #6
    New Coder
    Join Date
    Sep 2002
    Location
    Up North (UK)
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •