473,624 Members | 1,993 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing javascript variables to Perl

12 New Member
Hi

I have a html page with javascript in it that assigns a set of coordinates to javascript variables. The question I have is how can I then send these variables to a Perl CGI script using a submit on a html form.

An example of some of the code below:

Expand|Select|Wrap|Line Numbers
  1.     var map;
  2.     var geocoder = null;
  3.     var addressMarker;
  4.     var originpoint = null;
  5.  
  6. ....................
  7.  
  8.  
  9. function showAddress(address) {
  10.       if (geocoder) {
  11.         geocoder.getLatLng(address,
  12.           function(point1) {
  13.             if (!point1) {
  14.               alert(address + " not found");
  15.             } else {
  16.               if (addressMarker) {
  17.                 map.removeOverlay(addressMarker);
  18.               }
  19.               addressMarker = new GMarker(point1);
  20.               map.setCenter(point1, 15);
  21.               map.addOverlay(addressMarker);
  22.               originpoint = point1;
  23.               alert("origin is now: "+originpoint+" destination is now: "+destinationpoint);
  24.             }
  25.           }
  26.         );
  27.       }
  28.     }
  29.  
  30. <body onload="load()" onunload="GUnload()">
  31.     <form action="#" onsubmit="showAddress(this.address.value); return false">
  32.       <p>
  33.  Origin:<input type="text" size="50" id="addressInput" name="address" value="London, UK" />
  34.         <input type="submit" value="Show Origin" />
  35.       </p>
  36.     </form>
  37.  
  38.  
Now I want to be able to store the variable "originpoin t" and using another form to submit it to the perl CGI script. Any ideas?
Jul 20 '07 #1
8 5475
Harch84
12 New Member
Can anyone suggest an answer to this? I was thinking about some sort of hidden input form but am not sure how to implement it or how it would work?
Jul 20 '07 #2
pbmods
5,821 Recognized Expert Expert
Heya, Harch.

Easiest way to do it is to put them in the form. Create a couple of hidden inputs, then assign their values in the form's onsubmit.
Jul 21 '07 #3
Harch84
12 New Member
Hi Pbmods

I tried to do what you said but seem to be passing just the name of the variable not the actual value of the variable?

Expand|Select|Wrap|Line Numbers
  1.     <form action="http://morar.geos.ed.ac.uk/~s0679212/cgi_bin/sql_test.pl" method="POST" onSubmit="Origin">
  2.     <input type="hidden" name="Origin" value="originpoint">
  3.     <input type="Submit" value="Go!">
  4.     </form>
  5.  
In the perl script this returns the text "originpoin t" instead of the actual value of the variable originpoint from javascript. What am I doing wrong?
Jul 21 '07 #4
pbmods
5,821 Recognized Expert Expert
Heya Harch.

You have to use the onsubmit handler for your form and then use JavaScript to populate the form values:

Expand|Select|Wrap|Line Numbers
  1. <form ... onsubmit="return setVars();">
Expand|Select|Wrap|Line Numbers
  1. function setVars()
  2. {
  3.     document.getElementById('idOfInput') = variableName;
  4.     .
  5.     .
  6.     .
  7.     return true;
  8. }
  9.  
Jul 21 '07 #5
Harch84
12 New Member
Im really sorry about this but I still seem to be getting errors in my script preventing the javascrip variable to be passed to perl. I have used the advice given here and have this code:

Expand|Select|Wrap|Line Numbers
  1.     <script type="text/javascript">
  2.     //<![CDATA[
  3.  
  4.     function setVars()
  5.         {
  6.             document.getElementById('orig') = originpoint;
  7.             return true;
  8.         }
  9.  
  10.     //]]>
  11.     </script>
  12.  
  13.  
  14. <body onload="load()" onunload="GUnload()">
  15.  
  16. ........................ // other forms go here that use geocoder
  17.  
  18. <form action="http://morar.geos.ed.ac.uk/~s0679212/cgi_bin/sql_test.pl" method="POST" onsubmit="return setVars();">
  19. <input type="hidden" id="orig" name="Origin">
  20. <input type="Submit" value="Go!">
  21. </form>
  22.  
  23.   </body>
  24. </html>
  25.  
  26.  
Now the error I get is when I click on the submit button on the web page and it says that on the line 90 char 4 which is:

Expand|Select|Wrap|Line Numbers
  1.  
  2. 88    function setVars()
  3. 89    {
  4. 90        document.getElementById('orig') = originpoint;
  5. 91        return true;
  6. 92    }
  7.  
  8.  
The error says that there is a "Wrong number of arguements or invalid property assignment".??

As you can tell im no javascript expert so any help would be massivly appreciated and im sure its just something simple that I cant see but is obvious to you all. Thanks in advance
Jul 22 '07 #6
pbmods
5,821 Recognized Expert Expert
Heya, Harch.

You're getting close.

In that statement, you are trying to set the *element* to originpoint, which is what's giving JavaScript such a bellyache.

Instead, you want to set the element's *value* to originpoint:
Expand|Select|Wrap|Line Numbers
  1.  function setVars()
  2. {
  3.     document.getElementById('orig').value = originpoint;
  4.     return true;
  5. }
  6.  
Jul 22 '07 #7
Harch84
12 New Member
Heya Pbmods

That was the final part of the puzzle thanks so much for your help! Works perfectly now I almost cant believe it :-)

All the best

Harch
Jul 22 '07 #8
pbmods
5,821 Recognized Expert Expert
Heya, Harch.

Glad to hear you got it working! Good luck with your project, and if you ever need anything, post back anytime :)
Jul 22 '07 #9

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

Similar topics

9
2776
by: google_nospam | last post by:
Thanks in advance for any help. I'm looking for a way to pass data from php to perl. Basically, I want to take some dynamic data from a database, mixed with user input, then reformat it to make a new set of variables and pass those variables to a perl script to do all the hard work. Anyway, I can handle the database connectivity, and putting variables together, but how do I pass the variables to perl? I have seen other comments on...
1
9586
by: Joe | last post by:
I am trying to write a Perlscript to be used with some HTML pages. Here is how it works: 1.. The first HTML page has a form which requests for user input. Then it passes the QUERY_STRING to a Perl script. 2.. The Perl script will then validate the data. If input validation fails, it returns to the previous screen and asks the user to retry. If the validation passes, it display the user input and asks for confirmation.
1
3606
by: Consuelo Guenther | last post by:
Hello, I am having problems with passing variables between pages. I have the following: First asp page has the function: ----------------------------------------------------------------------- <script language="JavaScript"> function addProcess(addPName,addSProcess,addPIndex) { var addProcessWindow = window.open('second.asp','mywindow','width=400,height=200');
3
12869
by: Jeanne | last post by:
I am working on a cgi script that is suppose to pop-up a javascript box from the following perl variables:$TodayDate, $LinkCity, $LinkState. I recently encountered a problem with the $LinkCity variable when the city Coeur d'Alene was read. It appears that javascript is intrepreting the quote to end after d'. I've tried reversing the quotes (instead of " ' ' ", ' " " ') and using the javascript escape command. Neither worked. Please help!...
3
2781
by: Tommo | last post by:
Hello All, I am a still learning so be easy on me. I am trying to get some code to work that is using JS and Perl/CGI, I am using AS Perl and an Apache Server on XP as the webserver. Can anyone take a look at the code and tell me why I am getting Apache Server errors in the code below (Part A), when I modify the code as shown in part B the errors go but the JS does not run ?? Part A.
3
14927
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) { document.images.src = eval("mt" +menu+ ".src") } alert("imgOff_hidemenu"); hideMenu=setTimeout('Hide(menu,num)',500);
26
45497
by: Dave Hammond | last post by:
In document "A.html" I have defined a function and within the document body have included an IFRAME element who's source is document "B.html". In document "B.html" I am trying to call the function defined in "A.html", but every attempt results in an "is not a function" error. I have tried to invoke the function using parent.document.funcname(), top.document.funcname(), and various other identifying methods, but all result in the above...
1
3295
by: satish2112 | last post by:
Hi, I have a text-area which contains values from mysql database and 2 buttons, Edit and Update. When I click on the Edit button, I can edit the text-area (initially non-editable). After this, if I click on the Update button, the values in the text-area must be updated in the mysql database. I am storing the values of the text-area in a variable. I am using javascript to pass the variable.
5
5898
by: veeraiah | last post by:
Hi, I am new to PERL Scripting, i need your help with one of the problem i am having. I am having a PERL Script which has two variables $CurMon and $PriorMon. a Windows batch script calls this PERL Script. I want to return the values of the these two variables to the windows batch script. Can i do this? Please give me some suggestions. Thank You Chow
0
8236
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
8173
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8335
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,...
1
6110
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5563
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
4079
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
4174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2606
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
1
1785
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.