Reputation: 164
I am relatively new at Javascript, and I have a page that calls a javascript function on onkeyup
, but when called it throws an exception, Uncaught ReferenceError: validate is not defined
.
<script type="text/javascript">
function validate(id){
alert(id);
$.ajax({
url: "http://example.com/restaurant/submit/verify",
type: "POST",
dataType: 'json',
data: {
field: id,
content: $('#' + id).val()
}
success: function(data){
alert(data);
if(data.status == "PASSED"){
$('#' + id).removeClass('has-error');
$('#' + id).addClass('has-success');
} else if(data.status == "FAILED") {
$('#' + id).removeClass('has-success');
$('#' + id).addClass('has-error');
$('#' + id + ' div').append('<span class="help-inline">' + data.error + '</span>')
}
}
});
}
</script>
Any help is greatly appreciated, if you need more info, don't hesitate to ask. Thanks for any and all help.
Upvotes: 0
Views: 2076
Reputation: 622
You forgot a comma and a semicolon:
function validate(id){
alert(id);
$.ajax({
url: "http://example.com/restaurant/submit/verify",
type: "POST",
dataType: 'json',
data: {
field: id,
content: $('#' + id).val()
}, // Here
success: function(data){
alert(data);
if(data.status == "PASSED"){
$('#' + id).removeClass('has-error');
$('#' + id).addClass('has-success');
} else if(data.status == "FAILED") {
$('#' + id).removeClass('has-success');
$('#' + id).addClass('has-error');
$('#' + id + ' div').append('<span class="help-inline">' + data.error + '</span>'); // and here
}
}
});
}
Upvotes: 1