Results 1 to 5 of 5

Thread: Calling a javascript function

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2000
    Posts
    343

    Unhappy

    I have a javascript function on my page call checkout().

    How can I call this function from anywhere in my page.

    Presently I have it in my input statement like this..

    <input type="button" onclick="checkout()" value="submit">

    I want to be able to call this function anywhere/anytime in my page.

    Thanks

  2. #2
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606
    As simple as that :

    <script language=javascript>
    checkout();
    </script>

  3. #3
    Guest
    Something like this:


    <SCRIPT LANGUAGE="JavaScript">
    function myfunc(){
    //-----Do your function----->
    }
    </SCRIPT>


    And then you can call it whereever:


    <body onLoad="myfunc()">

    <input type="button" onclick="myfunc()" value="submit">


    etc.
    etc.

  4. #4
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    i think
    <input type="button" onclick="javascript:checkout()" value="submit">

    also works

  5. #5
    Guest
    Oops. da_silvy, javascript: function() is not needed. I don't believe you need the javascript: part.

    And there is an error in my code.


    This is incorrect:

    <body onLoad="myfunc()">

    <input type="button" onclick="myfunc()" value="submit">


    This is correct:

    <body onLoad="myfunc();">

    <input type="button" onclick="myfunc();" value="submit">

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width