You are viewing limited content. For full access, please sign in.

Question

Question

Forms: JQuery alert appears twice

asked on September 25, 2018

My form is configured to pop up an alert box when conditions are met. In the first function allotment, the alert box appears twice. I don't know why this would be.

$(document).ready(function() {
	$("#Field20").on('change', allotment);
    $("#Field47").on('change', evaluate);

	function allotment(){
		var ToDate = $('.ToDate input').val();
		var house = $('.total input').val();
            
		switch (true){
			case house == 1:
				var allow = 50;
				break;
			case house == 2:
				allow = 65;
				break;
			case house == 3:
				allow = 80;
				break;
			case house == 4:
				allow = 95;
				break;
			case house >= 5:
				allow = 110;
				break;
		}
		var availablePoints = +allow - +ToDate;
		alert("This guest has " + availablePoints + "/" + allow + " points remaining this week.");
      return false;
    }
  
  function evaluate(){
        var house = $('.total input').val();
        var cart = $('.cart input').val();
        var savedCount = $('.ToDate input').val();
        var newCount = +cart + +savedCount;
      
         
      if (house == 1 && newCount < 50) {
        alert("After today, there are " + (50 - newCount)
              + " food points remaining for the week.");
        
      } else if (house == 2 && newCount < 65) {
        alert("After today, there are " + (65 - newCount)
              + " food points remaining for the week.");
              
      } else if (house == 3 && newCount < 80) {
        alert("After today, there are " + (80 - newCount)
              + " food points remaining for the week.");
            
      } else if (house == 4 && newCount < 95) {
        alert("After today, there are " + (95 - newCount)
              + " food points remaining for the week.");
      
      } else if (house >= 5 && newCount < 110) {
        alert("After today, there are " + (110 - newCount)
              + " food points remaining for the week.");
            
      } else {
            alert("The maximum number of food points have been reached.");
        }
}  
});

 

0 0

Answer

SELECTED ANSWER
replied on September 25, 2018

Okay, so the double change event from #Field20 is probably a result of the lookup. Is this a field the user can edit?

If not, you could attach the event to the "lookupcomplete" event instead of "change"

0 0

Replies

replied on September 25, 2018

Do you have lookups or anything like that configured on the form? The simplest explanation would be that the change event for that field is being fired twice.

0 0
replied on September 25, 2018

I do have several lookups on the form. #Field20, '.total', '.ToDate' are all lookups. I am hoping to not be forced to completely reconfigure my form.

0 0
SELECTED ANSWER
replied on September 25, 2018

Okay, so the double change event from #Field20 is probably a result of the lookup. Is this a field the user can edit?

If not, you could attach the event to the "lookupcomplete" event instead of "change"

0 0
replied on September 25, 2018

#Field20 is also editable, though it may be edited 1% of the time. It sounds like a great option, thanks!

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.