2 Replies Latest reply on Aug 20, 2016 7:28 PM by Yogesh Deshpande

    How to set value returned by javascript to a form field

    Yogesh Deshpande
      Share:|

      I have a javascript that finds and masks credit card numbers of the input string provided.

      I want to be able to call it on LoseFocus of a CharField.

      On LoseFocus, the script shall run and the result returned by the script needs to be Set back to the CharField.

       

      Below is my javascript that I have copied to the WebHeader of the FormView. And I am doing a RunProcess : javascript validate_cc('$CharField$'); on Lose Focus

      ---------------------------------------------------------------------------------------------------------

      <script type="text/javascript">

      function validate_cc(value) {

                                                      var nCheck = 0, nDigit = 0, bEven = false;

                                                      if(value.length > 11){

                                                                      if (/[^0-9-\s]+/.test(value)) return false;

                                                                      value = value.replace(/\D/g, "");

                                                                      for (var n = value.length - 1; n >= 0; n--) {

                                                                                      var cDigit = value.charAt(n),

                                                                                      nDigit = parseInt(cDigit, 10);

                                                                      if (bEven) {

                                                                                      if ((nDigit *= 2) > 9) nDigit -= 9;

                                                                      }

                                                                      nCheck += nDigit;

                                                                      bEven = !bEven;

                                                      }

                                                      return (nCheck % 10) == 0;

                                      }

                                      return false;

                      }

      </script>

       

       

       

      Thank you,

      Yogesh