function call

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lynch

    function call

    How to call a javascript functio, but not from event (onClick, onChange,
    etc.) but juist from code (if something than some thing; else call a
    javascript function).


  • Peter Michaux

    #2
    Re: function call

    On May 23, 6:04 pm, "lynch" <mario.karlov.. .@foi.hrwrote:
    How to call a javascript functio, but not from event (onClick, onChange,
    etc.) but juist from code (if something than some thing; else call a
    javascript function).
    <script type="text/javascript">
    function myHandler() {
    alert('hi');
    }
    </script>

    <p id="foo" onclick="myHand ler()">click me</p>

    Then anywhere you want you can do this

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

    This is how I would probably share a handler.

    You could access the onclick property of the paragraph above but that
    does not seem like an good solution to me.

    document.getEle mentById('foo') .onclick();

    Peter

    Comment

    • Steve

      #3
      Re: function call

      On May 24, 3:04 am, "lynch" <mario.karlov.. .@foi.hrwrote:
      How to call a javascript functio, but not from event (onClick, onChange,
      etc.) but juist from code (if something than some thing; else call a
      javascript function).
      function sayHello() {
      alert("hello");
      }
      var a= 70;
      var b=30;
      if(a+b==100) {
      sayHello();
      }
      }

      Comment

      Working...