2

Thank you in advance for looking at this. :-)

The form validation itself works on other items where the field is simply required - that is no problem.

I am trying to set a numeric range for validation from my autocomplete dynamically.
I am using the bassistance.de JQuery validation found here.

Upon the select, I am calling a function, but it needs to be added to .validate() code instead of its own function (I think), but now sure how to combine them. The autocomplete is a generic function that is called by multiple inputs.

<script>
   $().ready(function() {
       // validate the form when it is submitted
       $("#form4100").validate();
   });
</script>
<script>
function Autocomplete(numberLocation,nameLocation,dscLocation,chargeLocation,amountLocation) {
    select: function( event, ui ) {          
            $(numberLocation).val( ui.item.value );
            $(nameLocation).html( ui.item.desc );                     
            alert("Minimum Investment: "+ui.item.minimum);
            setvalidation(amountLocation,ui.item.minimum);
            return false;
    }        
}

function setvalidation(amountLocation,minimum){
    alert("validation function launched");
    amountLocation.validate({
      rules: {
        field: {
          required: true,
          range: [minimum, 5000000]
        }
      }
    });    
}
</script>

Thanks!

1 Answer 1

4

I found out (after reading the docs further on the validation plugin) that there is a .rules add method. So the .select can call this function:

function setvalidation(amountLocation,minimum){
    amountLocation.rules("add",{
                  required: true,
                  range: [minimum, 5000000],
                  messages: {
                      range: "$ "+minimum + " Minimum"
                 }                             
    }); 
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.