Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

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 ( [id://1104666]=note: print w/replies, xml ) Need Help??


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

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

  • Comment on Re^2: Perl and jQuery to select mutiple elements from dropdown by checking checkboxes (multipeColorSelect.pl)
  • Select or Download Code

Replies are listed 'Best First'.
Re^3: Perl and jQuery to select mutiple elements from dropdown by checking checkboxes (multipeColorSelect.pl)
by Anonymous Monk on Oct 22, 2014 at 11:56 UTC
    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.
Re^3: Perl and jQuery to select mutiple elements from dropdown by checking checkboxes (multipeColorSelect.pl)
by Anonymous Monk on Oct 22, 2014 at 12:11 UTC
    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.

        Here is my advice, go to http://jsfiddle.net/, and set up your attempt at solving this, share your jsfiddle with the stackoverflow and someone might help you

        Don't mention perl anymore, its a jquery/html question ... perl isn't involved anymore

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1104666]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-20 01:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found