Here’s my code
<script type="text/javascript" href="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript" href="js/js.js"></script>
...
<input type="text" name="city" onkeyup="loadStation(this.value);"/>
...
and the js.js file
//Load Stations
function loadStation(stationCity){
alert(stationCity);
}
When I try to trigger the loadStation onkeyup, nothing’s happening. The path of js/js.js is ok since in the source I can load it.
What could be wrong ?
EDIT
I fell really stupid…. instead of href=”” it should have been src=””. The funiest thing is that even you guys haven’t notice it 😛
Thanks
You could be wrong about `js/js.js`
I’d suggest using Firebug and checking that you’re not getting a 404 error from your js file.
You may have wanted to use a root-relative link to the js file: `/js/js.js` so that you don’t have issues with sub-directories.
I’ve often professed the beauty of HTML CSS & JavaScript as an MVC pattern. So I wont go into that here, however. You should keep your HTML in
.htmlfiles, your CSS in.cssfiles, and your JavaScript in.jsfilesUsing inline javascript event attributes breaks the nice MVC pattern that I often describe, so it’s much better to attach the events in the script itself:
Fiddle
A couple more debugging questions:
* Are you testing a flat html & js file locally?
* Are you uploading flat files to a server?
* Are you able to post a url of where the content is located?
You’re using
hrefinstead ofsrcon thescriptelement.