I am trying to run a JavaScript/jQuery function and Firebug gets the error:
$ is not defined $(function()".
The JavaScript code is placed inside a file called core.js and referenced by index.php. What causes this error?
JavaScript:
<script type="text/javascript">
var formObject = {
run : function(obj) {
if (obj.val() === '') {
obj.nextAll('.update').html('<option value="">----</option>').attr('disabled', true);
} else {
var id = obj.attr('id');
var v = obj.val();
jQuery.getJSON('/mod/update.php', { id : id, value : v }, function(data) {
if (!data.error) {
obj.next('.update').html(data.list).removeAttr('disabled');
} else {
obj.nextAll('.update').html('<option value="">----</option>').attr('disabled', true);
}
});
}
}
};
$(function() {
$('.update').live('change', function() {
formObject.run($(this));
});
});
</script>
PHP/HTML
<html>
<select name="main" id="category" class="update">
<option value="">Select one</option>
<? if (!empty($list)) { ?>
<? foreach($list as $row) { ?>
<option value="<?php echo $row['id']; ?>">
<? echo $row['name']; ?>
</option>
<? } ?>
<? } ?>
</select>
</html>