Instead of a while-loop, alert the error message and return false:
if(checkblanks(form) === false) {
alert("Please fill in all numeric values");
return false;
}
After all, you cannot continue, and the user should use the submit/go button again after he corrected his mistakes. Also, continuously checking things isn't the way to go in JavaScript, instead, you would listen to events, such as form value changes, and react on them.
The duplicate answer issue
The first action in operations
is to add an event listener to the submit button:
function operations(form) {
$(".button").click(function () { //after form submission
$(".matrix").slideUp(1000, function () { //hiding the matrix form
$("#answer").slideDown(1000); //and display the answer
});
});
You do this in order to hide the .matrix
and in order to show the answer, whenever the button is pressed after this. However, that's not what you actually want to do. Instead, you want to hide the .matrix
and show the #answer
at this point. Instead of adding an event listener, do the actions exactly at this point:
function operations(form) {
$(".matrix").slideUp(1000, function () { //hiding the matrix form
$("#answer").slideDown(1000); //and display the answer
});
// ...
Even better, do those steps at the end of operations, right after you edited the innerHTML
of your answer.