I'm using jQuery with the validation plugin when I submit a form:
$('.frmProject:visible').validate( {
errorContainer: ".site_details:visible .messageBox1",
errorLabelContainer: ".site_details:visible .messageBox1 span.messagehere",
invalidHandler: function(form, validator) {
},
rules: {
site_id: {
required: true,
}
},
messages: {
site_id: "Project has no assigned site information. Click the marker on the map at left to specify the site where this project took place."
},
submitHandler: function(data) {
SaveProject();
}
});
In the submitHandler,
function SaveProject(){
//... load variables with input contents
$.ajax({
url: 'ajax/save_project.php',
dataType: 'json',
data: 'id='+id+'&title='+title+'&project='+project+'§or='+sector+'&volunteer='+volunteer+'&lat='+lat+'&lng='+lng+'&name='+name+'&mun='+mun+'&prov='+prov,
success: function(data) {
//... load 'messages' object with stuff
$.each(messages, function(key, value) {
if (confirm(key)){
console.log(item);
}
});
}
});
}
When I submit the validated form and it gets to the confirm inside the each loop, I get the error message: "confirm is not a function".
How can I present a message to the user for confirmation?
Edit:
When I type "confirm" into the console I get this:
Inspecting in DOM reveals:
window > confirm() There are no properties to show for this object.
Inspecting in Script takes me to a place in jquery-1.6.2.min.js
If you assign a variable without var, you are assigning that variable to the global space. In your case there was a string assigned to the confirm variable that overrode the native confirm method.
Defining any html object with attribute id ="confirm" also causes this error
I use both 'jquery confirm' and 'datatables', in my case, 'datatables' should be imported before 'jquery confirm'.
So, in some case, try ReOrder ........
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With