473,698 Members | 2,528 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

11 New Member
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 6141
eWish
971 Recognized Expert Contributor
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
getmadhu
11 New Member
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 Recognized Expert Contributor
Where are you getting the value of $var? Is it user input?

--Kevin
Mar 18 '08 #4
getmadhu
11 New Member
eWish..

Yes, It is the input variable I am getting from the database.
Mar 18 '08 #5
eWish
971 Recognized Expert Contributor
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
getmadhu
11 New Member
Thank you eWish for you efforts to help me out...

Some one plzz...help me
Mar 18 '08 #7
KevinADC
4,059 Recognized Expert Specialist
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 New Member
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 Recognized Expert Specialist
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

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

Similar topics

46
3508
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 by pointer in C++, is there such way in Python? Thansk in advance. J.R.
0
3318
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 appear when someone is trying to use it as front-end for real server database systems such as PostgreSQL or MySQL. One of these problems is regarding pass-through queries and parameters. I wanted to have all the code on client, while executing it on...
10
2503
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++) { items = "item" + (i + 1);
2
4873
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 #!/ois/usr/bin/perl -w use strict; use CGI qw(:standard); my $cgi=new CGI; my $flg=0;
0
2191
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 http://myhomepage.html?var1=test1&var2=test2.. These variable could be anything that is entered by user. Now I need to get these variables an pass those values in my javascript function as parameter. Thanks in advance for help..
3
2414
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 program the URL to download the other program from. So I need to work out how I can do the same thing without having a hard coded URL in the file. It is an executable generated from a C compiler so I don't want customers to have to edit a C source...
1
1619
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 function from perl. (I am using cgi.pm). I created a HTML button, and I am calling the javascript with the "onClick" property. Like this: Perl: -onClick=>"myFunction($a, $b)" Java: function myFunction(myA, myB) { stuff...}
5
13992
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 button? I searched a few things on Google but I find the javascript below most useful in my case but there is some problem that my code is not running: var test = document.getElementsByName("meal"); for (i = 0; i < test.length; i++) {
12
11092
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. Here is a newbie mistake that I found myself doing (as a newbie), and that even a master programmer, the guru of this forum, Jon Skeet, missed! (He knows this I'm sure, but just didn't think this was my problem; LOL, I am needling him) If...
0
8680
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9169
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8899
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8871
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7738
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5861
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4371
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.