Reputation: 4304
I'm trying to call a function inside a form validation function, but it's not working. The function confirm_submit should be called if valid is true.
$(document).ready(function() {
$("#dialog").dialog({
autoOpen: false,
buttons : {
"Confirm" : function() {
$('#form').submit();
},
"Cancel" : function() {
$(this).dialog("close");
}
}
});
function confirm_submit(){
$("#dialog").dialog('open');
}
});
function validate(){
valid = true;
if ( document.form.number.value == ""){
alert ( "You need to complete the Number field." );
valid = false;
return valid;
}
if(valid){
confirm_submit();
}
}
Upvotes: 0
Views: 365
Reputation: 7735
It's because your definition for confirm_submit
is scoped inside your document.ready
event. Move the definition after });
right above function validate(){
.
This is basically what you're doing:
function x() {
function y() {
console.log('y')
}
console.log('x');
y();
}
function z() {
console.log('z');
y(); // throws: ReferenceError: y is not defined
}
Upvotes: 1