By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,742 Members | 1,206 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,742 IT Pros & Developers. It's quick & easy.

Pass variables from Perl to Ajax and back

P: 30
Hi everybody, I'm creating a website with HTML / Javascript embeded in perl code. I use perl to get values from a MySQL database which I need to feed a chart created with the javascript code so the chart can be updated on the fly. Everything works perfectly well except I don't know how the perl variable values can be passed to the javascript within the same document.

Here is abbreviated example code:

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -w
  2. use CGI;
  3. use sctrict;
  4.  
  5. $Type = 'line';
  6. $width = '200';
  7. $line_color ='#FF0000';
  8. $fillColor = '#FFFF00',
  9. $height = '20';
  10.  
  11. ### I NEED TO POPULATE THE BELOW DOTED LINES WITH THE ABOVE VARIABLES  ###
  12.  
  13. print q~
  14.  
  15.   <script>
  16.  
  17.     $(document).ready(function () {
  18.  
  19.      $("#sparkline4").sparkline([34, 43, 43, 35, 44, 32, 15, 22, 46, 33, 86, 54, 73, 53, 12, 53, 23, 65, 23, 63, 53, 42, 34, 56, 76, 15, 54, 23, 44], {
  20.             type: '........',
  21.             lineColor: '.....', 
  22.             fillColor: '.......',
  23.             width: '......',
  24.             height: '.....'
  25.         });
  26.  
  27.    });
  28.  
  29. var hellow_world: 'Hello World';
  30.  
  31. </script>
  32. ~;
  33.  
  34. $HELLO_WORLD = "..........";
  35.  
  36. ### ----- END OF PERL CODE ---- ### 
  37.  

Also I need to do this the other way around. The value of the hellow_worl javascript variable need to populate the dots in the $HELLO_WORLD perl variable.

Thanx a million
webvirtual
May 4 '17 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.