Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Drop down menus with html and perl

ocYrusocYrus Member Posts: 15
Ok what i want to do(and i am having trouble with 1 little thing) is to create a page where u select from a list then click submit and it displays items from the list u selected.

Let says i wanted to select Doctor so i clicked on it from the dropdown menu list and then clicked submit. Then when the code was ran it would run a if statement finding out which one of the lists the user chose then displayed everything that was under that list. here is the code i have so far just having trouble with getting the if statment in there.

heres the html



ok






Dentist
Doctor
Health
Life
Car









heres the cgi

#!/usr/bin/perl

use strict;
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);

my $doctor = param('doctor');
my $dentist = param('dentist');
my $health = param('health');
my $life = param('life');
my $car = param('car');

print header;
if ($doctor);
open(OK, "./ok");
my $ok = ;
$ok =~ tr/ok/ok/;
print $ok;
close(OK);


Comments

  • DrGonzoDrGonzo Member Posts: 41
    I had a better reply to your post that explained a couple of logic errors in your code and also explained why the big 'if' block below is better then the quick and simple one line ($data_file_name = "$data_list_name.dat";). But, unfortunately, this message board logged me out and then destroyed my submission when I tried to post, sooooo, I'm just posting the simple alternative code and accompanying html that I tried to submit at the end of my original post attempt. If you want me to show you the errors in your other code, just post a reply asking for it.




    ok





    [b][/b]

    Dentist
    Doctor
    Health
    Life
    Car








    #!/usr/bin/perl

    use strict;
    use CGI qw(:standard);
    use CGI::Carp qw(fatalsToBrowser);

    my $data_list_name = lc(param('list_to_display'));
    my $data_file_name = "";

    if($data_list_name eq "doctor")
    {
    $data_file_name = "doctor.dat";
    #Any other doctor specific code goes here
    }
    elsif($data_list_name eq "dentist")
    {
    $data_file_name = "dentist.dat";
    #Any other dentist specific code goes here
    }
    elsif($data_list_name eq "health")
    {
    $data_file_name = "health.dat";
    #Any other heatlth specific code goes here
    }
    elsif($data_list_name eq "life")
    {
    $data_file_name = "life.dat";
    #Any other life specific code goes here
    }
    elsif($data_list_name eq "car")
    {
    $data_file_name = "car.dat";
    #Any other car specific code goes here
    }

    print header;

    if($data_file_name ne "")
    {
    open(DATAFILE, "./$data_file_name");
    my $data = ;
    print $data;
    close(DATAFILE);
    }


  • mbabarkamranmbabarkamran Member Posts: 2
    DrGonzo

    Hi there,

    Could you be kind enough to tell me the logical errors. i greatly like your post and answer it solved my problem accurately. If possible then kindly pinpoint some URLs.

    Thanks and Take Care,
  • mbabarkamranmbabarkamran Member Posts: 2
    DrGonzo

    Hi there,

    Could you be kind enough to tell me the logical errors. i greatly like your post and answer it solved my problem accurately. If possible then kindly pinpoint some URLs.

    Thanks and Take Care,
Sign In or Register to comment.