Button calling multiple functions

A

allanrodkin

Hi,

I am a newbie. I am programming in Perl and dynamically generating
html. I want to call two functions on the click of a button, one a
javascript function and also a Perl function. Is there a way to do
this. So far I am using the following code but I don't know how to
include a call to a second function in the tag

$html .= qq`\n<input type=button value="deletestyle" name=
"deletestyle"
onclick="JavaScript:do_deletestyle()">`;

Thanks,
Fred
 
D

David Dorward

I am a newbie. I am programming in Perl and dynamically generating
html. I want to call two functions on the click of a button, one a
javascript function and also a Perl function.

Perl almost always runs on the server, JavaScript almost always runs on the
client.

So you would /probably/ do something like:

<form action="myPerlScript.pl" onsubmit="someJavaScriptFunction()">
<div>
<input type="submit">
</div>
</form>

OR

You would have your Perl script output something along the lines of:

<script type="text/javascript">
someJavaScriptFunction();
</script>

.... depending on what data needed to be sent to the Perl script and what
order you wished the JavaScript function and Perl subroutine to run in.
 
A

allanrodkin

Hi Mr. Dorward,
I have a couple questions about the first solution you gave.

<form action="myPerlScript.pl" onsubmit="someJavaScriptFuncti­on()">
<div>
<input type="submit">
</div>
</form>

Forgive me for my ignorance in this matter. Using this code, I'm
assuming the JavaScript function executes first. If so, how do you
return the values you want from the JavaScript function so I can send
them to the perl script?


Thanks,
Fred
 
J

Jonathan N. Little

Hi Mr. Dorward,
I have a couple questions about the first solution you gave.

<form action="myPerlScript.pl" onsubmit="someJavaScriptFuncti­on()">
<div>
<input type="submit">
</div>
</form>

Forgive me for my ignorance in this matter. Using this code, I'm
assuming the JavaScript function executes first. If so, how do you
return the values you want from the JavaScript function so I can send
them to the perl script?


Thanks,
Fred
If it is a posting to a form, then have some input fields, usually
'hidden' for this purpose that the JavaScript sets their value before
submition of the form.

<script type="text/javascript">
function someJavaScriptFunction(){
var f=document.forms[0];
...
f.toBeSet.value="Some Value Derived by JavaScript";
...
return true;
}
</script>

....

<form action="myPerlScript.pl" onsubmit="someJavaScriptFunction()>
<input type="hidden" name="toBeSet">
....
</form>
 
B

Benjamin Niemann

Jonathan said:
Hi Mr. Dorward,
I have a couple questions about the first solution you gave.

<form action="myPerlScript.pl" onsubmit="someJavaScriptFuncti­on()">
<div>
<input type="submit">
</div>
</form>

Forgive me for my ignorance in this matter. Using this code, I'm
assuming the JavaScript function executes first. If so, how do you
return the values you want from the JavaScript function so I can send
them to the perl script?


Thanks,
Fred
If it is a posting to a form, then have some input fields, usually
'hidden' for this purpose that the JavaScript sets their value before
submition of the form.

<script type="text/javascript">
function someJavaScriptFunction(){
var f=document.forms[0];
...
f.toBeSet.value="Some Value Derived by JavaScript";
...
return true;
}
</script>

...

<form action="myPerlScript.pl" onsubmit="someJavaScriptFunction()>
<input type="hidden" name="toBeSet">
...
</form>

Also note that the return value of JS function (always 'true' in the example
above) determines, if the form will actually be submitted (and if your perl
script on the server will be executed). Returning 'false' will prevent the
form submission (but you can't stop non-JS users from submitting the form
of course).
 
H

Hilarion

I have a couple questions about the first solution you gave.
<form action="myPerlScript.pl" onsubmit="someJavaScriptFuncti­on()">
<div>
<input type="submit">
</div>
</form>

Forgive me for my ignorance in this matter. Using this code, I'm
assuming the JavaScript function executes first. If so, how do you
return the values you want from the JavaScript function so I can send
them to the perl script?
If it is a posting to a form, then have some input fields, usually
'hidden' for this purpose that the JavaScript sets their value before
submition of the form.

<script type="text/javascript">
function someJavaScriptFunction(){
var f=document.forms[0];
...
f.toBeSet.value="Some Value Derived by JavaScript";
...
return true;
}
</script>
...
<form action="myPerlScript.pl" onsubmit="someJavaScriptFunction()>
<input type="hidden" name="toBeSet">
...
</form>

Also note that the return value of JS function (always 'true' in the example
above) determines, if the form will actually be submitted (and if your perl
script on the server will be executed). Returning 'false' will prevent the
form submission (but you can't stop non-JS users from submitting the form
of course).


For this to work you'll have to change onsubmit="someJavaScriptFunction()"
to onsubmit="return someJavaScriptFunction()".


Hilarion
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top