Button calling multiple functions

Discussion in 'HTML' started by allanrodkin@hotmail.com, Aug 23, 2005.

  1. Guest

    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
     
    , Aug 23, 2005
    #1
    1. Advertising

  2. wrote:

    > 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.

    --
    David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
    Home is where the ~/.bashrc is
     
    David Dorward, Aug 23, 2005
    #2
    1. Advertising

  3. Guest

    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
     
    , Aug 24, 2005
    #3
  4. wrote:
    > 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>

    --
    Take care,

    Jonathan
    -------------------
    LITTLE WORKS STUDIO
    http://www.LittleWorksStudio.com
     
    Jonathan N. Little, Aug 24, 2005
    #4
  5. Jonathan N. Little wrote:

    > wrote:
    >> 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).

    --
    Benjamin Niemann
    Email: pink at odahoda dot de
    WWW: http://www.odahoda.de/
     
    Benjamin Niemann, Aug 24, 2005
    #5
  6. Hilarion Guest

    >>> 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
     
    Hilarion, Aug 24, 2005
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ryan Ternier
    Replies:
    4
    Views:
    4,014
    Cowboy \(Gregory A. Beamer\) [MVP]
    Jul 29, 2004
  2. Xiangliang Meng
    Replies:
    1
    Views:
    1,631
    Victor Bazarov
    Jun 21, 2004
  3. Daniel Vallstrom
    Replies:
    2
    Views:
    1,943
    Kevin Bracey
    Nov 21, 2003
  4. S?ren Gammelmark
    Replies:
    1
    Views:
    1,929
    Eric Sosman
    Jan 7, 2005
  5. Ross A. Finlayson
    Replies:
    19
    Views:
    623
    Keith Thompson
    Mar 10, 2005
Loading...

Share This Page