1

I have installed Eclipse along with the Web Developer tools -- I am trying to do Javascripting in Eclipse but wanted to know if there are specific other plug-ins/kits I need in order to do so. Currently I build using:

File -> New -> Web -> Dynamic Web Project ||
File -> New -> HTML File ||
File -> New -> JSP File

To be able to run JavaScript as the materials I am learning/working off of. However I am unable to have any JavaScript event handling capabilities in the Eclipse environment.

As an example I have the following HTML file:


<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<script src="keyboardTest.js"></script>
<title>pageTest</title>
</head>
<body>

</body>
</html>

---------------------

And keyboardTest.js file:

---------------------


alert("inside keyboardTest.js");

var main = function(){

$(document).keypress(function(event){
    alert("HERE");
     if(event.which === 65){
        /** A  **/
        alert("A");
    }
    else if(event.which == 69){
         /** E  **/
        alert("E");
    }
     else if(event.which===70){
        /** F  **/
        alert("F");
    }
    else if(event.which===32){
        /** SPACE_BAR **/
        alert("space_bar");
    }
});
}


$(document).ready(main)`

But the HTML doesn't trigger the Javascript within the inner function main--it does however send the very first ALERT(). Concurrently when I move the files to a directory on my computer the javascript ALERT works, but not the event readers.

1 Answer 1

1

You're using jQuery syntax here: $(document) But you haven't included the jQuery framework to you html file. Add jQuery and it should work:

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks that worked! I've been doing online courses and they left out that bit about including the jQuery library

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.