Firefox Form introduces jQuery issue

I use the following script to submit a form with jQuery, however Firefox generated a crash error report, tell me what I'm doing wrong.

function teamValidation(){ var cat_id = $('#cat_id').val(); if(cat_id == "0"){ alert("Category is invalid..."); return false; }else{ $('#addForm').submit(); return false; } } <form action="<?php echo SITE_URL; ?>adminteams/saveDetail/" name="addForm" id="addForm" onsubmit="return teamValidation();"> <input type="hidden" name="cat_id" id="cat_id" value="1"/> </form> 

Firefox Bug Report

enter image description here

It works great in other browsers.

+6
source share
4 answers

The problem is that your form is submitted multiple times. You can achieve your goal using any of the following methods:
HTML:

 <form action="<?php echo SITE_URL; ?>adminteams/saveDetail/" name="addForm" id="addForm"> <input type="hidden" name="cat_id" id="cat_id" value="1"/> </form> 

JAVASCRIPT:

 $('#addForm').submit(function(){ var cat_id = $('#cat_id').val(); if(cat_id == "0"){ alert("Category is invalid..."); return false; }else{ return true; } }); 

Another way:
HTML:

 <form action="<?php echo SITE_URL; ?>adminteams/saveDetail/" name="addForm" id="addForm" onsubmit="return teamValidation();"> <input type="hidden" name="cat_id" id="cat_id" value="1"/> </form> 

JAVASCRIPT:

 function teamValidation(){ var cat_id = $('#cat_id').val(); if(cat_id == "0"){ alert("Category is invalid..."); return false; }else{ return true; } } 
+5
source

You have an infinite submit loop, and then preventing your form from submitting when the value of the cat_id text field cat_id not 0. Remove the else block as it does not serve the actual purpose.

More details:

 function teamValidation(){ var cat_id = $('#cat_id').val(); if(cat_id == "0"){ alert("Category is invalid..."); return false; }else{ $('#addForm').submit(); // this submits the form again - does NOT proceed with this submission of the form return false; // returning false will prevent the submission from being completed } } <form action="<?php echo SITE_URL; ?>adminteams/saveDetail/" name="addForm" id="addForm" onsubmit="return teamValidation();"> <input type="hidden" name="cat_id" id="cat_id" value="1"/> </form> 

When submitting a form, teamValidation() called. If the check teamValidation() else block code is executed), you submit the form again , which calls teamValidation() again , then return false , which will prevent this current teamValidation() from ending, Firefox probably fails, because it is in a loop where it constantly submits a form that is never allowed to complete; the fact that the browser is pretty awful in terms of memory usage probably doesn't help either.

+2
source

You forgot to close your function definition

 function teamValidation(){ var cat_id = $('#cat_id').val(); if(cat_id == "0"){ alert("Category is invalid..."); return false; }else{ $('#addForm').submit(); return false; } } <--- this 
0
source

You missed the '}' at the end. However, it should not cause failures. 99% problems installing Firefox. I just checked with me here. Works correctly. You have no problem with your code. Try uninstalling and reinstalling Firefox.

Another discovery. Your form is submitted indefinitely. Perhaps your other browsers are newer and your Firefox is outdated (unable to handle undefined recursions, so it may crash).

In any case, try replacing the following:

 $('#addForm').submit(); 

from:

 document.getElementById("addForm").submit(); 

Hope this helps.

Peace to you...

0
source

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


All Articles