in reply to Re: embed jquery in perl
in thread embed jquery in perl

Apologies for forgetting to mention that... It's simply a perl console script (no CGI involved etc) which will download the html. I want to use jquery simply to parse the html

Replies are listed 'Best First'.
Re^3: embed jquery in perl
by marto (Cardinal) on Jan 02, 2014 at 15:50 UTC

    I see. How do you fetch the HTML? Does JavaScript populate the values of these checkboxes? Do you have some example HTML you could post?

    Update: If possible it may help if you posted the perl code you currently have.

      Currently, I haven't written any perl code yet. I'm still in the planning phase. I thought it might be possible to use jQuery.get to grab the page. If not, I can use either a perl module or curl/wget. The html is really not all that exciting. It has a bunch of input checkboxes that are checked manually (via human input). No javascript involved here. After retrieving the html, I was hoping to do something like this:
      <form> <div> <input type="checkbox" name="fruit" value="orange" id="orange"> <label for="orange">orange</label> </div> <div> <input type="checkbox" name="fruit" value="apple" id="apple"> <label for="apple">apple</label> </div> <div> <input type="checkbox" name="fruit" value="banana" id="banana"> <label for="banana">banana</label> </div> <div id="log"></div> </form> <script> $( "input" ).on( "click", function() { $( "#log" ).html( $( "input:checked" ).val() + " is checked!" ); }); </script>
      and somehow pull the identifiers of the checkboxes that are checked into a perl data structure. Again, thank you for your help here.

        There are some problems here. HTML::JQuery does not embed jQuery, allowing you to run jQuery code like the example you have provided. jQuery requires a JavaScript capable browser to run. Secondly this HTML has no values checked. This example is valid for jQuery running in a web browser, the log div will update to indicate which fruit is checked. I think you need to take a step back and figure out how the technologies in question actually work. To get values from a webpage they have to be submitted, the old fashioned way or the AJAX way, then server side processing of the values can take place.