The following code should pop up an alert box whenever I select a file or make a change to the textbox and click out of it.
I believe the code SHOULD work, but it doesn’t. Isolating the code snippets on JSFiddle and running them even works.
Is anything wrong with my code? If not, could something on my computer be preventing this code from working?
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(function() {
document.getElementById("file").onchange(function() {
alert($(this).val());
});
$('#text').change(function() {
alert($(this).val());
});
});
</script>
</head>
<body>
<input id="file" type="file" name="file" />
<input id="text" type="text" name="text" />
</body>
</html>
Try wrapping your function in
jsfiddle does this for you (I think)
Alternatively use:
if you want to ensure that the entire page has loaded before trying to run your code.
Further reading:
http://docs.jquery.com/Tutorials:Introducing_$(document).ready()