JavaScript error says "confirmation is not a function"

I use jQuery with a validation plugin when submitting 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 submitHandler

 function SaveProject(){ //... load variables with input contents $.ajax({ url: 'ajax/save_project.php', dataType: 'json', data: 'id='+id+'&title='+title+'&project='+project+'&sector='+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 a validated form and it receives confirmation within each cycle, I get an error message: "confirmation is not a function."

How can I submit a message to the user for confirmation?

Edit:

When I type โ€œconfirmโ€ in the console, I get the following:

Screen capture of console output

A check in the DOM shows:

window> confirm () There are no properties for this object.

Testing in Script will lead me to a place in jquery-1.6.2.min.js

+5
source share
3 answers

If you assign a variable without var, you assign this variable to global space. In your case, there was a line assigned to the confirmation variable that overrides your own confirmation method.

+15
source

The confirmation method is part of the window object.

 if (window.confirm(key)){ console.log(item); } 
+15
source

I use both "jquery Validation" and "datatables", in my case, "datatables" must be imported before "JQuery Validate".

So, in some cases, try ReOrder ........

0
source

Source: https://habr.com/ru/post/1380317/


All Articles