0

Here's the code:

When I try to load the function myList() on page load Console shows "mylist entered" in Chrome, Opera but doesn't seem to work in Firefox.

However the function myList() works(even in Firefox) from inside the keyup function which I have commented in the below code:

<!DOCTYPE html>
<html>
<head>
    <title>List</title>

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script>
        console.log('ready');
    $(function () {
        // body...
        $('#omnibox').focus();
        if (window.localStorage) {
            //Enter key binding
            var todo = document.querySelector('#omnibox');
            //debugger;
            $('#omnibox').keyup(function(e){
                if(e.keyCode == 13)
                {
                    console.log("Enter pressed!");
                    var todoVal = document.querySelector('#omnibox').value;
                    //myList(); 

                }
            });
            myList();
            function myList()
                {
                    console.log("mylist entered");
                }
        }

    });
    </script>
</head>
<body>
<h2>List</h2>
    <input type="text" id="omnibox">
    <div id='searchWrapper'>
    </div>
</body>
</html>
  • 1
    Don't put the function definition inside the `if`. That seems to be deferring the function definition until it gets to that code, which is after you try to call it. – Barmar Feb 05 '15 at 06:31
  • excellent answer by barmar also try putting some meta tags for errors removal see this link http://stackoverflow.com/questions/11996257/the-character-encoding-of-the-html-document-was-not-declared – kki3908050 Feb 05 '15 at 06:55
  • Add this as a first line in the HEAD section of your HTML template – kki3908050 Feb 05 '15 at 06:56
  • Thanks everyone for the help :) – AwesomeSid Mar 16 '15 at 06:41

0 Answers0