in reply to Perl and jQuery to select mutiple elements from dropdown by checking checkboxes

I have updated my question.

Yes, I see, its an improvement, but it needs more

Where is the perl program that focuses on one goal? (remember Re: Need help to improve pagination )

So you want a perl function to print some html stuff

and you want that function ( someHtmlStuff ) to print different html stuff based on some value of checkbox1 one and checkbox2, correct?

So this is the function you write

someHtmlStuff( \%allColors, \%mainColors, $checkbox1, $checkbox2 ) ;

And these are the possibilities , this is the beginning of your program (like Re: Need help to improve pagination )

someHtmlStuff( \%allColors, \%mainColors, undef, undef ); someHtmlStuff( \%allColors, \%mainColors, 0, 0 ); someHtmlStuff( \%allColors, \%mainColors, 1, 0 ); someHtmlStuff( \%allColors, \%mainColors, 1, 1 ); someHtmlStuff( \%allColors, \%mainColors, 0, 1 );

This is where you begin, now keep going

Replies are listed 'Best First'.
Re^2: Perl and jQuery to select mutiple elements from dropdown by checking checkboxes (multipeColorSelect.pl)
by Anonymous Monk on Oct 22, 2014 at 10:02 UTC
    Here is the next step, keep improving this program
    #!/usr/bin/perl -- ## multipeColorSelect.pl ## ## 2014-10-22-02:58:36 ## ## ## ## ## ## ## perltidy -olq -csc -csci=3 -cscl="sub : BEGIN END " -otr -opr -ce +-nibc -i=4 -pt=0 "-nsak=*" ## perltidy -olq -csc -csci=10 -cscl="sub : BEGIN END if " -otr -opr +-ce -nibc -i=4 -pt=0 "-nsak=*" ## perltidy -olq -csc -csci=10 -cscl="sub : BEGIN END if while " -otr + -opr -ce -nibc -i=4 -pt=0 "-nsak=*" #!/usr/bin/perl -- use strict; use warnings; use Carp::Always; Main( @ARGV ); exit( 0 ); sub Main { my %allColors = ( 1 => 'Red', 2 => 'Yellow', 3 => 'Orange', 4 => 'Blue', 5 => 'Black', 6 => 'Brown', 7 => 'Green', 8 => 'White', ); my %mainColors = ( 1 => 'Red', 2 => 'Yellow', 3 => 'Orange', 4 => 'Blue', ); print multipeColorSelect( \%allColors, \%mainColors, 0, 0 ); print multipeColorSelect( \%allColors, \%mainColors, 1, 0 ); #~ print multipeColorSelect( \%allColors, \%mainColors, 1, 1 ); #~ print multipeColorSelect( \%allColors, \%mainColors, 0, 1 ); } ## end sub Main ### FIRST VERSION, THE STUB #~ sub multipeColorSelect { #~ ## my( $all, $main, $checkMain, $checkReset ### RESET?!?!?!? #~ ## my( $all, $main, $selectMain, , $checkRest #~ my( $all, $main, $selectMain, $selectRest ) = @_; #~ return q{ #~ <select id="multipeColorSelect" multiple size="8"> #~ <option value="Red" class="maincolor">Red</option> #~ <option value="Orange" class="maincolor">Orange</option> #~ <option value="Green" class="maincolor">Green</option> #~ <option value="White" class="maincolor">White</option> #~ <option value="Yellow">Yellow</option> #~ <option value="Blue">Blue</option> #~ <option value="Black">Black</option> #~ <option value="Brown">Brown</option> #~ </select> #~ }; #~ } ## end sub multipeColorSelect ### FIRST IMPROVEMENT , FIRST CONDITION, DEFAULT CONDITION, no checkbo +xes selected sub multipeColorSelect { my( $all, $main, $selectMain, $selectRest ) = @_; if( not $selectMain and not $selectRest ) { return q{ <select id="multipeColorSelect" multiple size="8"> <option value="Red" class="maincolor">Red</option> <option value="Orange" class="maincolor">Orange</option> <option value="Green" class="maincolor">Green</option> <option value="White" class="maincolor">White</option> <option value="Yellow">Yellow</option> <option value="Blue">Blue</option> <option value="Black">Black</option> <option value="Brown">Brown</option> </select> }; } else { die "todo"; } } ## end sub multipeColorSelect __END__

    This is what happens when I run it (looks good so far)

    $ perl multipeColorSelect.pl <select id="multipeColorSelect" multiple size="8"> <option value="Red" class="maincolor">Red</option> <option value="Orange" class="maincolor">Orange</option> <option value="Green" class="maincolor">Green</option> <option value="White" class="maincolor">White</option> <option value="Yellow">Yellow</option> <option value="Blue">Blue</option> <option value="Black">Black</option> <option value="Brown">Brown</option> </select> todo at multipeColorSelect.pl line 82. main::multipeColorSelect('HASH(0x99bbf4)', 'HASH(0xa1019c)', 1 +, 0) called at multipeColorSelect.pl line 41 main::Main() called at multipeColorSelect.pl line 19

    Next step, return some different static html for different selecdtMain and selectRest value combinations

      I dont want perl function to print some html stuff. I want jQuery as I showed in my code. But, when checkbox is checked, how do we call values from hash?

        You are aware that the jQuery function does not run on your server?

        You can make a jQuery.get() (or jQuery.ajax()) request to load data that is served from Perl. But this is Perlmonks, not jQuerymonks, so for programming Javascript and jQuery, you have to go somewhere else.

        can i interject to recommend the Template Toolkit for you to conditionally display select options based on the checkbox value outside the perl script.

        Is jQuery a client/customer requirement, or is it something u can replace ? Using TT, every time u need to tweak your display logic, you dont have to look at changing your perl code.
      And i dont want to use this. This was my example.
      <select id="multipeColorSelect" multiple size="8"> <option value="Red" class="maincolor">Red</option> <option value="Orange" class="maincolor">Orange</option> <option value="Green" class="maincolor">Green</option> <option value="White" class="maincolor">White</option> <option value="Yellow">Yellow</option> <option value="Blue">Blue</option> <option value="Black">Black</option> <option value="Brown">Brown</option> </select>
      Instead I want to call values from hash from dropdown when checkbox is checked.
        Please reply.