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: -
var map;
-
var geocoder = null;
-
var addressMarker;
-
var originpoint = null;
-
-
....................
-
-
-
function showAddress(address) {
-
if (geocoder) {
-
geocoder.getLatLng(address,
-
function(point1) {
-
if (!point1) {
-
alert(address + " not found");
-
} else {
-
if (addressMarker) {
-
map.removeOverlay(addressMarker);
-
}
-
addressMarker = new GMarker(point1);
-
map.setCenter(point1, 15);
-
map.addOverlay(addressMarker);
-
originpoint = point1;
-
alert("origin is now: "+originpoint+" destination is now: "+destinationpoint);
-
}
-
}
-
);
-
}
-
}
-
-
<body onload="load()" onunload="GUnload()">
-
<form action="#" onsubmit="showAddress(this.address.value); return false">
-
<p>
-
Origin:<input type="text" size="50" id="addressInput" name="address" value="London, UK" />
-
<input type="submit" value="Show Origin" />
-
</p>
-
</form>
-
-
Now I want to be able to store the variable "originpoint" and using another form to submit it to the perl CGI script. Any ideas?
8 5434
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?
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.
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? -
<form action="http://morar.geos.ed.ac.uk/~s0679212/cgi_bin/sql_test.pl" method="POST" onSubmit="Origin">
-
<input type="hidden" name="Origin" value="originpoint">
-
<input type="Submit" value="Go!">
-
</form>
-
In the perl script this returns the text "originpoint" instead of the actual value of the variable originpoint from javascript. What am I doing wrong?
Heya Harch.
You have to use the onsubmit handler for your form and then use JavaScript to populate the form values: - <form ... onsubmit="return setVars();">
-
function setVars()
-
{
-
document.getElementById('idOfInput') = variableName;
-
.
-
.
-
.
-
return true;
-
}
-
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: -
<script type="text/javascript">
-
//<![CDATA[
-
-
function setVars()
-
{
-
document.getElementById('orig') = originpoint;
-
return true;
-
}
-
-
//]]>
-
</script>
-
-
-
<body onload="load()" onunload="GUnload()">
-
-
........................ // other forms go here that use geocoder
-
-
<form action="http://morar.geos.ed.ac.uk/~s0679212/cgi_bin/sql_test.pl" method="POST" onsubmit="return setVars();">
-
<input type="hidden" id="orig" name="Origin">
-
<input type="Submit" value="Go!">
-
</form>
-
-
</body>
-
</html>
-
-
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: -
-
88 function setVars()
-
89 {
-
90 document.getElementById('orig') = originpoint;
-
91 return true;
-
92 }
-
-
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
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: -
function setVars()
-
{
-
document.getElementById('orig').value = originpoint;
-
return true;
-
}
-
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
Heya, Harch.
Glad to hear you got it working! Good luck with your project, and if you ever need anything, post back anytime :)
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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:
-----------------------------------------------------------------------...
|
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...
|
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...
|
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) {...
|
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...
|
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,...
|
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...
|
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
|
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...
|
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,...
|
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...
|
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,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
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...
|
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...
|
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,...
| |