Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set variable value to jquery message + jquery.validate

How to get value of var total in message,

and also i tried declare inside function but it gives undefined variable

var total = '';
$.validator.addMethod("valueNotEquals", function (value, element, arg) {
    var fund_old = $("#current_fund").val();
    var fund_new = $("#new_fund").val();

    total = parseFloat(9999999999.999999) - parseFloat(fund_old);

    if (parseFloat(fund_new) <= parseFloat(total)) {
        return true;
    } else {
        return false;
    }
    return true;
}, 'sry sktiman' + total + 'is remaining value');

In result i am getting blank value of total

like image 791
SagarPPanchal Avatar asked Sep 11 '25 19:09

SagarPPanchal


1 Answers

According to the documentation for jQuery.validator.addMethod() you can use jQuery.validator.format() which generates a function that receives the arguments to the validation method and returns a string message, so creating a function that ignores any arguments and returns a string should work:

var total = '';
$.validator.addMethod("valueNotEquals", function (value, element, arg) {
    var fund_old = $("#current_fund").val();
    var fund_new = $("#new_fund").val();

    total = parseFloat(9999999999.999999) - parseFloat(fund_old);

    if (parseFloat(fund_new) <= parseFloat(total)) {
        return true;
    } else {
        return false;
    }
    return true;
}, function() {return 'sry sktiman' + total + 'is remaining value'});

EDIT

The fiddle for this solution can be found here (thanks to Sparky for providing the code).

like image 136
juan.facorro Avatar answered Sep 13 '25 10:09

juan.facorro