$ is not defined
Posted: Mon Feb 16, 2009 8:01 pm
I have a page called register.php which contains javascript that I posted at the end of the post. Register.php is called via ajax and i had this working but something changed and my error console is replying lookupUser is not defined. I also tried to place the javascript in a .java file and include it to the page which says the $ is not defined and highlights a few lines from fillAddie like $('#zip').val(zip);
Everything works correctly if i directly access register.php but this is not how my site operates. How can I make this work again. Also feel free to help improve my javascript as I am not too fluent with it yet.
Everything works correctly if i directly access register.php but this is not how my site operates. How can I make this work again. Also feel free to help improve my javascript as I am not too fluent with it yet.
Code: Select all
<script type="text/javascript">
function lookupZip(inputString) {
if(inputString.length == 0) {
// Hide the suggestion box.
$('#suggestions').hide();
} else {
$.post("http://url.com/inc/php/ajax.php", {queryString: ""+inputString+""}, function(data){
if(data.length >0) {
$('#suggestions').show();
$('#autoSuggestionsList').html(data);
}
});
}
}
function fillAddie(zip, state, city) {
$('#zip').val(zip);
$('#state').val(state);
$('#city').val(city);
setTimeout("$('#suggestions').hide();", 200);
}
function lookupUser(inputString) {
if(inputString.length == 0) {
// Hide the suggestion box.
$('#suggestions').hide();
} else {
$.post("http://url.com/inc/php/ajax.php", {username: ""+inputString+""}, function(data){
if(data.length > 0)
showErrorLayer('errorUser');
else
hideErrorLayer('errorUser');
});
}
}
function hideErrorLayer(lay){
if (document.layers)
document.layers[lay].display = 'none';
else if (document.all)
document.all[lay].style.display = 'none';
else if (document.getElementById)
document.getElementById(lay).style.display = 'none';
}
function showErrorLayer(lay){
if (document.layers)
document.layers[lay].display = 'block';
else if (document.all)
document.all[lay].style.display = 'block';
else if (document.getElementById)
document.getElementById(lay).style.display = 'block';
}
function checkform(form){
if (form.email.value == "" ||form.email.value==null) {
document.getElementById('error').innerHTML="A valid email address is required.";
showErrorLayer('error');
form.email.focus();
return false;
}
if (form.firstName.value == "" ||form.firstName.value==null) {
document.getElementById('error').innerHTML="Your first name cannot be blank.";
showErrorLayer('error');
form.firstName.focus();
return false;
}
if (form.lastName.value == "" ||form.lastName.value==null) {
document.getElementById('error').innerHTML="Your last name cannot be blank.";
showErrorLayer('error');
form.lastName.focus();
return false;
}
if (form.user.value == "" ||form.user.value==null) {
document.getElementById('error').innerHTML="A username is required.";
showErrorLayer('error');
form.user.focus();
return false;
}
if (form.pass.value == "" ||form.pass.value==null) {
document.getElementById('error').innerHTML="A strong password is required.";
showErrorLayer('error');
form.pass.focus();
return false;
}
if (form.zip.value == "" ||form.zip.value==null) {
document.getElementById('error').innerHTML="A valid zip code is required.";
showErrorLayer('error');
form.zip.focus();
return false;
}
if (form.state.value == "" ||form.state.value==null) {
document.getElementById('error').innerHTML="A valid state is required.";
showErrorLayer('error');
form.state.focus();
return false;
}
if (form.agreeTerms.checked == false) {
document.getElementById('error').innerHTML="You must agree to the sites terms.";
showErrorLayer('error');
form.agreeTerms.focus();
return false;
}
return true ;
}
</script>