Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jan 2011
    Posts
    42
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Chrome issue while calling Js function defined in html file

    Hi,


    I'm trying to call a Js function from a test.js located in a HTML file.

    I'm getting error message "Object has no method..." in Chrome. But no issues are seen in Firefox. Can any one please let me know how i can fix this.

    <html>
    <head>
    ....
    ....
    ....
    <div>
    <html>
    <head>
    <script src="test.js"></script>
    <script>
    function aFunc()
    {
    alert ("Inside aFunc");
    }
    </script>
    </head>
    <body>
    </html>
    ....
    ....
    ....
    </div>
    </head>
    </html>

    test.js

    function bFunc ()
    {
    aFunc ();
    }

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,398
    Thanks
    12
    Thanked 570 Times in 563 Posts
    Quote Originally Posted by htmlster View Post
    I'm trying to call a Js function from a test.js located in a HTML file.
    Code:
    <html>
    <head>
    ....
    ....
    ....
    <div>
    <html>
    <head>
    <script src="test.js"></script>
    <script>
    function aFunc()
    {
    alert ("Inside aFunc");
    }
    </script>
    </head>
    <body>
    </html>
    ....
    ....
    ....
    </div>
    </head>
    </html>
    test.js
    Code:
    function bFunc ()
    {
    aFunc ();
    }
    Questions:

    1. You are not calling ANY function in this piece of code you are showing. Where is the function call you are talking about?
    2. Your HTML is totally messy ... it has opening and closing tags all over the place, mostly where they don't belong. Is this your actual code or some kind of "mass typo"?

  • #3
    New Coder
    Join Date
    Jan 2011
    Posts
    42
    Thanks
    1
    Thanked 0 Times in 0 Posts
    If you observe closely there is an html document within a div. There are two html tags in the overall file when you view in browser. I'm calling aFunc from bFunc defined in test.js.

    Assume that bFunc is getting called when some external event is triggered.

  • #4
    Regular Coder
    Join Date
    Aug 2010
    Posts
    970
    Thanks
    19
    Thanked 212 Times in 210 Posts
    Quote Originally Posted by htmlster View Post
    Assume that bFunc is getting called when some external event is triggered.
    No don't assume that bFunc is being called.
    Put an alert in bFunc to be sure.
    The code you have posted works
    for me when bFunc is called like this.

    Code:
    <html>
    <head>
    ....
    ....
    ....
    <div>
    <html>
    <head>
    <script src="test.js"></script>
    <script>
    function aFunc()
    {
    alert ("Inside aFunc");
    }
    
    bFunc();
    
    </script>
    </head>
    <body>
    </html>
    ....
    ....
    ....
    </div>
    </head>
    </html>
    maybe your problem is somewhere else


  •  

    Posting Permissions

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