www.webdeveloper.com
Results 1 to 4 of 4

Thread: [RESOLVED] onchange Doesn't Trigger Function Call

Hybrid View

  1. #1
    Join Date
    Jul 2010
    Location
    Cobalt, Ontario, Canada
    Posts
    15

    resolved [RESOLVED] onchange Doesn't Trigger Function Call

    THIS WORKS:

    <html><head><script type="text/javascript">
    function recalc() {
    alert ('Entering recalc().');
    }
    </script></head><body>
    <form><input name="tf_addr" id="tf_addr" type="text"></form>
    <script type="text/javascript">recalc()</script>
    </body></html>


    THIS WORKS:

    <html><head><script type="text/javascript">
    </script></head><body>
    <form><input name="tf_addr" id="tf_addr" type="text" onchange="alert('onchange works fine')"></form>
    </body></html>


    BUT THIS DOESN'T WORK:

    <html><head><script type="text/javascript">
    function recalc() {
    alert ('Entering recalc().');
    }
    </script></head><body>
    <form><input name="tf_addr" id="tf_addr" type="text" onchange="recalc()"></form>
    </body></html>


    The first example works, which shows that the recalc function can be called. The second example works, which shows that onchange will trigger an alert box. BUT, the third example doesn't work. Why can't I trigger a call to the recalc function from the onchange event?

    The above 3 code postings are the entire programs. Nothing has been left out or modified.

    I am using IE 8.0.6001.18702.

    I am sure the solution is simple enough, but I'm just not seeing it. Can anyone out there help me?

  2. #2
    Join Date
    Aug 2007
    Posts
    3,767
    recalc is the problem. Change the name and it will work.
    Great wit and madness are near allied, and fine a line their bounds divide.

  3. #3
    Join Date
    Jul 2010
    Location
    Cobalt, Ontario, Canada
    Posts
    15

    Thanks, Declan

    Many thanks, Declan. Your solution works fine.

    If I may bother you one more time: Why does this solve the problem?

  4. #4
    Join Date
    Aug 2007
    Posts
    3,767
    For the same reason that you don't make functions called alert. recalc seems to be a propitiatory function of IE that does some re-calculation, what exactly I don't know.

    The other one you might run into is that all ids are global variables in IE. So don't name a function the same as an id on the page.
    Great wit and madness are near allied, and fine a line their bounds divide.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles