in reply to Select Category dropdowns?

Anonymous, let me see if I have you right: You want us to go through a couple hundred lines of your code which you know doesn't work and figure out why it doesn't work without you providing us with anything more than the entire, ugly block of code? You didn't even get your post right, ysth had to edit it for you to make it readable!

What have you already tried? What errors are you getting? What exactly do you expect it to do? What parts of the code do you know aren't the problem (and why have you included them)?

You really need to narrow down your problem and post a specific test-case that fails. We're here to help you with the last 5-10% of your project, we expect you to do most of the trouble-shooting. Otherwise, hire a Perl consultant (there are several here).

Oh yeah, why are you trying to do sub-menus with Perl? As much as I love it (and promote it's use whenever it fits the bill), java(script) is much more suited to the task.

- - arden.

Replies are listed 'Best First'.
Re^2: Select Category dropdowns?
by efret (Initiate) on Jul 12, 2004 at 05:09 UTC
    Oops, I did not make progress... Simple question? Can I make a Main Cat Dropdown that brings up a Sub Cat dropdown in perl? example: <FORM ACTION=$ENV{'SCRIPT_NAME'} METHOD=POST> print "<OPTION value=$key>@mycategory{$key}</OPTION>", <FORM ACTION=$ENV{'SCRIPT_NAME'} METHOD=POST> print "<INPUT TYPE='SUBMIT' NAME=action VALUE='go'>", "</select>", print "(the subcat, and other form info) "</select>", If not, can I call my existing cats & subcats from a JS script? and how? Thanks

      Hi efret welcome to the Monestary. Please have a look at Tutorials under the Welcome to the Monestary Heading. You need to use <code> tags around your code so we can read it. Also the probability of getting a good answer is roughly inversly proportional to the quantity of code you post - aka distill the question down to a very simple case. We don't have time to read hundreds of lines of irrelevant code.

      Anyway. The answer you seek: It is more of a javascript problem. Here is good tutorial on exactly how you do it. Where the author uses php you can use perl (ie to deliver data from a DB to the second select list without having to refresh the page by using an iframe). As you can see the bulk of the work is done in js.

      Fixed typo PodMaster

      cheers

      tachyon

        Hi, Nice javascript solution!!! I thought you were PERLMONKS, not JAVAMONKS??? I know how to do this in javascript!!! Can I create Perl Dynamic Dropdowns within a form? If so, how?
Re^2: Select Category dropdowns?
by efret (Initiate) on Jul 12, 2004 at 04:49 UTC
    Hi, No, I'm not asking anyone to go through all the code i posted... I did post a test url...I have tried online manuals, multiple forums, and i can't find any info on dynamic Perl forms... The Error I am getting is I can bring up the correct subcat page, but can't get the 2nd dropdown to display the subcats, when I select a cat from the 1st dropdown...and can't get my subcats into a dropdown box? I expect to create a Main Cat dropdown that, when a Main Cat is selected, a 2nd dropdown displays the respective subcats...until there are no more cats, then displays, No More Cats... The "Post new Item" form works fine...I am just trying to create dynamic dropdowns inside this form??? I posted the entire sub to let anyone who knows Perl, see what I am trying to do... I made progress again, but still aint there??? I removed the 1st dropdown code and for some reason, I am still displaying a dropdown at the top...if you pick a cat from the top dropdown, then hit the go button in the "Select Category" dropdown, it goes to that category page...but if you select a cat in the "select category" dropdown, it doesn't change? I still need to find out how to make the 1st dropdown populate the 2nd dropdown with the correct sub cat list??? Heres my test script: www.efret.com/cgi-bin/test/test35.pl Heres the code:
    #-############################################# # Sub: Add New Item # This allows a new item to be put up for sale sub new { my ($title, $reserve, $inc, $desc, $image, $buyit, @bids); my $inc = '1.00'; # default increment if ($form{'REPOST'}) { $form{'REPOST'} =~ s/\W//g; if (-T "$config{'basepath'}$config{'closedir'}/$form{'REPOST'}.dat") + { open THEFILE, "$config{'basepath'}$config{'closedir'}/$form{'REPOST'}.dat"; ($title, $reserve, $inc, $desc, $image, $buyit, @bids) = <THEFILE>; close THEFILE; chomp($title, $reserve, $inc, $desc, $image, $buyit, @bids); } } print <<"EOF"; <!-- Add the following line to add a back button - between (print <<"E +OF";) & (EOF) --> <input type="button" name="Button" value="Back" onClick="MM_callJS('i +f (history.length &gt; 0){history.back()}')"> ##################### # Post new Item Form <FORM ACTION=$ENV{'SCRIPT_NAME'} METHOD=POST> <H2>Post A New Item</H2> <TABLE WIDTH=100% BORDER=1 BGCOLOR=$config{'colortablebody'}> <INPUT TYPE=HIDDEN NAME=action VALUE=procnew> <TR><TD VALIGN=TOP><B>Title/Item Name:<BR></B>No HTML</TD><TD><INPUT N +AME=TITLE VALUE=\"$title\" TYPE=TEXT SIZE=50 MAXLENGTH=50></TD></TR> <TR><TD VALIGN=TOP><B>Category:<BR></B>Select One</TD><TD> ##################### # Select Main Cat pulldown ###################################################################### +##################### print "<form ACTION=$ENV{'SCRIPT_NAME'} method=post> ", my $catinfo="<!--$form{category}-->";$catinfo=~s/\:/--><!--/g;$catinf +o=~s/<!---->//g; umask(000); my($key, %numfiles, %mycategory, %caticon); foreach $key (keys %category) { next if $category{$key}!~/^\Q$catinfo\E/; opendir(THEDIR, "$config{'basepath'}$key") || mkdir("$config{'basepath'}$key", 0777) || &oops("Category directory $k +ey could not be opened."); readdir THEDIR;readdir THEDIR; my @allfiles = readdir THEDIR; closedir THEDIR; if($category{$key} =~ /^\Q$catinfo\E<!--([^>]*)-->/ && $supercat{$1} + ne ''){ $mycategory{"$form{category}:$1"} = $supercat{$1}; $numfiles{"$form{category}:$1"} += @allfiles; $caticon{"$form{category}:$1"} = $config{supercaticon}; }else{ $mycategory{$key} = $category{$key}; $numfiles{$key} += @allfiles; $caticon{$key} = $config{regularcaticon}; } } my $cols = $config{maincatcols} || 2; my $pc = int(100/$cols); print "<select name=category>", my @keys = sort {lc $mycategory{$a} cmp lc $mycategory{$b}} keys %myc +ategory; my $definedkeys = $#keys + $cols-(($#keys+1)%$cols); my $cmove = int(@keys/$cols); $cmove++ if (@keys%$cols); for(my $i = 0;$i<=$cmove-1;$i++) { # print "<tr>"; my $j = $i; for(1..$cols){ my $key=$keys[$j]; if($key ne ''){ print "<OPTION value=$key>@mycategory{$key}</OPTION>", }else{ print( # Print Padding (Empty Cells) "<td>&nbsp;</td>", ); } $j+=$cmove; } } print ( "<INPUT TYPE='SUBMIT' NAME=action VALUE='go'>", "</select>", "</tr>", ); ###################################################################### +##################### ##################### </SELECT></TD></TR> ######################### <TR><TD VALIGN=TOP><B>Image URL:<BR></B>Optional, should be no larger +than 200x200</TD><TD><INPUT NAME=IMAGE VALUE=\"$image\" TYPE=TEXT SIZE=50 VALUE="http://"></TD></TR> <TR><TD VALIGN=TOP><B>Days Until Close:<BR></B>1-30</TD><TD><INPUT NAM +E=DAYS TYPE=TEXT SIZE=2 MAXLENGTH=2></TD></TR> <TR><TD VALIGN=TOP><B>Description:<BR></B>May include HTML - This shou +ld include the condition of the item, payment and shipping information, and any other information the buyer should know.</TD><TD><TEXTAREA NAME=DE +SC ROWS=5 COLS=45>$desc</TEXTAREA></TD></TR> <TR><TD COLSPAN=2 VALIGN=TOP>Please note that by placing an item up fo +r bid you are making a contract between you and the buyer.<br> Once you place an item, you may not retract it and you must sell it fo +r the highest bid.<br> In other words, if you don't want to sell it, don't place it up for bi +d! EOF if ($config{'regdir'}) { print <<"EOF"; <P><B><A HREF="$ENV{'SCRIPT_NAME'}?action=reg">Registration</A> is req +uired to post or bid!</B></TD></TR> <TR><TD VALIGN=TOP><B>Your Handle/Alias:<BR></B>Used to track your pos +t</TD><TD><INPUT NAME=ALIAS TYPE=TEXT SIZE=30 MAXLENGTH=30> <TR><TD VALIGN=TOP><B>Your Password:<BR></B>Must be valid</TD><TD><INP +UT NAME=PASSWORD TYPE=PASSWORD SIZE=30> <TR><TD VALIGN=TOP><B>Your Starting Bid:</B></TD><TD>\$<INPUT NAME=BID + TYPE=TEXT SIZE=7 VALUE=0> <TR><TD VALIGN=TOP><B>Your Reserve Price:<BR></B>You are not obligated + to sell below this price. Leave blank if none.</TD><TD>\$<INPUT NAME=RESERVE TYPE=TEXT S +IZE=7 VALUE=0> <!-- ############################ --> <TR><TD VALIGN=TOP><B>Bid Increment:</B></TD><TD>\$<INPUT NAME=INC TYP +E=TEXT SIZE=7 VALUE="$inc"></TD></TR> <TR><TD VALIGN=TOP><B>Buy-it Now:</B><BR>Optional, this feature allows + the first bidder to win the auction with a bid at this set price.</TD><TD>\$<INPUT NAME="B +UYIT" TYPE="text" SIZE="7"></TD></TR></TABLE> <!-- ############################ --> EOF } else { print <<"EOF"; </TD></TR> <TR><TD VALIGN=TOP><B>Your Handle/Alias:<BR></B>Used to track your pos +t</TD><TD><INPUT NAME=ALIAS TYPE=TEXT SIZE=30 MAXLENGTH=30> <TR><TD VALIGN=TOP><B>Your E-Mail Address:<BR></B>Must be valid</TD><T +D><INPUT NAME=EMAIL TYPE=TEXT SIZE=30> <TR><TD VALIGN=TOP><B>Your Starting Bid:</B></TD><TD>\$<INPUT NAME=BID + TYPE=TEXT SIZE=7 VALUE=0> <TR><TD VALIGN=TOP><B>Your Reserve Price:<BR></B>You are not obligated + to sell below this price. Leave blank if none.</TD><TD>\$<INPUT NAME=RESERVE TYPE=TEXT S +IZE=7 VALUE=0> <TR><TD VALIGN=TOP><B>Bid Increment:</B></TD><TD>\$<INPUT NAME=INC TYP +E=TEXT SIZE=7 VALUE="$inc"> <!-- ############################ --> <TR><TD VALIGN=TOP><B>Buy-it Now:</B><BR>Optional, this feature allows + the first bidder to win the auction with a bid at this set price.</TD><TD>\$<INPUT NAME="B +UYIT" TYPE="text" SIZE="7"> <!-- ############################ --> <TR><TD VALIGN=TOP><B>Contact Information:<BR></B>Will be given out on +ly to the buyer</TD><TD> <TT>Full Name: </TT><BR><INPUT NAME=ADDRESS1 TYPE=TEXT SIZE=30><BR> <TT>Street Address: </TT><BR><INPUT NAME=ADDRESS2 TYPE=TEXT SIZE=30><B +R> <TT>City, State, ZIP: </TT><BR><INPUT NAME=ADDRESS3 TYPE=TEXT SIZE=30> +</TD></TR></TABLE> EOF } print <<"EOF"; <CENTER>Adult Content IS NOT Allowed!!! <INPUT TYPE=SUBMIT VALUE=Previ +ew></CENTER> EOF }
    Javascript may be the answer, but I don't know how to integrate it with my cat & subcat variables yet!!!,( I don't want to have to enter my 18000 cats/Subcats another time) and was hoping to do this in Perl... Now what? Any help is appreciated?

    20040711 Edit by ysth: add code tags