473,406 Members | 2,439 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

How can i pass and access a Perl var parameter in a Javascript function

Hi All,

How can i pass a Perl var($val) as a parameter to a Javascript function.

Please can any one help me out...

ex:
Perl Code
----------------
Expand|Select|Wrap|Line Numbers
  1. $var = 'sample'
  2. <select name="sample" onChange="lbChange('sample');">
instead of above I want to pass the perl var

Expand|Select|Wrap|Line Numbers
  1. <select name="sample" onChange="lbChange($var);">
Javascript
---------------
Expand|Select|Wrap|Line Numbers
  1. function lbChange(lbName) {
  2.    if (lbName == 'sample') {
  3. alert ("Value:"+ lbname);
  4. }
  5.  
in the above function how can I retreive the $var of perl
Mar 18 '08 #1
10 6094
eWish
971 Expert 512MB
You might be able to use a templating system that would allow you to embed perl code in the template file that could handle this for you. Check at CPAN for a templating system like Mason or Template Toolkit.

--Kevin
Mar 18 '08 #2
Thanks Kevin for the response...

Is there any other way with out using the CPAN module.. because I already wrote a huge no. of lines of code(Perl/CGI/HTML/Javascript).. So, I don't want to change the whole thing. It will mess up completely....

I searched a lot to get that.. still I am unable to get the sol.. If any one help me this. really I will be very thank full to him
Mar 18 '08 #3
eWish
971 Expert 512MB
Where are you getting the value of $var? Is it user input?

--Kevin
Mar 18 '08 #4
eWish..

Yes, It is the input variable I am getting from the database.
Mar 18 '08 #5
eWish
971 Expert 512MB
You could include this line in your script and print it to the browser after the value has been populated.

Expand|Select|Wrap|Line Numbers
  1. <select name="sample" onChange="lbChange($var);">
But I don't know of a way other than a templating system or refreshing of the browser to achieve what you are after. Maybe someone else will.

--Kevin
Mar 18 '08 #6
Thank you eWish for you efforts to help me out...

Some one plzz...help me
Mar 18 '08 #7
KevinADC
4,059 Expert 2GB
Thank you eWish for you efforts to help me out...

Some one plzz...help me
The short answer is you can't. Javascript executes in the browser while perl code executes on the remote server. The only way they communicate is via CGI forms. Now your perl code can print the javascript code and fill in values in the javascript using perl variables up to the time the javascript is printed out. After that you have to send data back to the perl script to rewrite the javascript. If you wanted to do that without reloading the entire page, you want to look into AJAX. I have no experience with AJAX so I can't help with code.
Mar 18 '08 #8
arggg
91
The short answer is you can't. Javascript executes in the browser while perl code executes on the remote server. The only way they communicate is via CGI forms. Now your perl code can print the javascript code and fill in values in the javascript using perl variables up to the time the javascript is printed out. After that you have to send data back to the perl script to rewrite the javascript. If you wanted to do that without reloading the entire page, you want to look into AJAX. I have no experience with AJAX so I can't help with code.
Is perl creating the html? If so can't you just have it print out the variable just like as if you were using PHP? For example.

Expand|Select|Wrap|Line Numbers
  1. echo "<a href=\"#\" onClick=\"javascript:Test('".$PHP_VAR."');>Link</a>";
Mar 18 '08 #9
KevinADC
4,059 Expert 2GB
Is perl creating the html? If so can't you just have it print out the variable just like as if you were using PHP? For example.

Expand|Select|Wrap|Line Numbers
  1. echo "<a href=\"#\" onClick=\"javascript:Test('".$PHP_VAR."');>Link</a>";
Did you read what I posted? Plus that is what eWish already posted too. But I guess it's cool to post it again just in case the OP hasn't gotten the message yet.
Mar 18 '08 #10
Hi frnds,

Thanks a lot.. Problem got resolved... I just sent the $var to javascript function as an argument and taken into a js variable.

<script type="javascript">
initParam($var)
</script>
Mar 19 '08 #11

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

Similar topics

46
by: J.R. | last post by:
Hi folks, The python can only support passing value in function call (right?), I'm wondering how to effectively pass a large parameter, such as a large list or dictionary? It could achieved...
0
by: Zlatko Matić | last post by:
Hi everybody! Recently I was struggling with client/server issues in MS Access/PostgreSQL combination. Although Access is intuitive and easy to use desktop database solution, many problems...
10
by: Sean Dockery | last post by:
I have the following HTML file that I've been using for testing... <html> <head> <script type="text/javascript"> <!-- function handleWindowLoad() { var items = ; for (var i = 0; i < 11; i++)...
2
by: pleaseexplaintome | last post by:
Hi I have the following perl/cgi script snippet. The goal of this script is to pass a javascript variable to perl where it can be re-used later. Any help is appreciated, Thanks ...
0
by: alpha122 | last post by:
I am beginner and I need some help writing simple perl script. I need to get url query and pass it to the javascript function as parameter. for example: my page will be...
3
by: Angus | last post by:
I have a program which when downloaded from a server downloads another program from the same web server and then configures the downloaded program. The trouble is I have to hard code in the...
1
by: adpinc | last post by:
Hello all! I am a seasoned programmer, but not really with Javascript. I have a strange phenomenon going on that for the life of me I cannot figure out what is wrong. I am calling a javascript...
5
by: JohnDriver | last post by:
Hi, I am having a form which has a text box and 3 radio buttons. I am using GET method in Ajax to pass the value. I can pass the value of the textbox fine but how to pass the value of radio...
12
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms....
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.