Conditional Error Text – JavaScript Question

0

Anyone might know what is wrong with this JS? As you can tell I am VERY new to this code, and in need of a helping hand. Thank you in advance for any help!!

BEst,

Mihaly

Here is the code (that doesn’t work):

//submit validation
$(‘.sg-survey-form’).submit(function(e){

var emp_us = $(‘#sgE-2826644-19-9-element’); //emp_us
var emp_ma = $(‘#sgE-2826644-19-93-element’); //emp_ma

$errortxt = ‘Your MA based employees can not be greater than your total number of US employees’;

if($emp_us < $emp_ma) {
//alert($tgtbox.val());

$(‘.sg-error-message’).text($errortxt).fadeIn(‘slow’);
e.preventDefault();

}
}); //end submit validation
});

Jacob H (Moderator) answered
    0

    Hi,

    When I checked out the code I found the following items, not sure if they will fix the problem, but I took a stab at it:

    1. The single quote is a different character that my editor did not parse correctly, I replaced it in the code below.
    2. I added a “$” to the beginning of the var declarations, to be consistent with your if statement.

    $(‘.sg-survey-form’).submit(function(e){

      var $emp_us = $(‘#sgE-2826644-19-9-element’); //emp_us
      var $emp_ma = $(‘#sgE-2826644-19-93-element’); //emp_ma

      $errortxt = ‘Your MA based employees can not be greater than your total number of US employees’;

      if($emp_us < $emp_ma) {
        //alert($tgtbox.val());

        $(‘.sg-error-message’).text($errortxt).fadeIn(‘slow’);
        e.preventDefault();

        }
      }); //end submit validation
    });

    Let me know how that works for you.

    Jacob H (Moderator) edited answer
      ×

      Login

      Question stats

      • Active
      • Views267 times
      • Answers1 answer
      • Followers1 follower