0

here is my html

<input class="required" id="AcceptTerms" name="AcceptTerms" type="checkbox" value="true" aria-required="true">

here is my JavaScript

//make sure user accepts terms 
$('form').validate({
    rules: {
        AcceptTerms: 'required'
    },
    messages: {
        AcceptTerms: 'You should accept terms in order to proceed'
    }
});

and the error message is 'This field is required.'

why is it not displaying my custom message ?

1
  • Can you make fiddle? Which jQuery plugin are you using? Commented Aug 25, 2015 at 10:37

2 Answers 2

2

Form validation runs on submiting form:

You can see complete code example on jsfiddle

<form>
<input class="required" id="AcceptTerms" name="AcceptTerms" type="checkbox" value="true" aria-required="true">
<br/>
<input type="submit" value="Validate!">
</form>

JS code is bellow:

$( 'form' ).validate({
  rules: {
    AcceptTerms : 'required'

  },
  messages: {
      AcceptTerms : 'You should accept terms in order to proceed'
  }
});

Both examples, works, see fiddle.

Sign up to request clarification or add additional context in comments.

1 Comment

Ok it works but its not the same as your code here, overthere it shows required: true
-1

I have written simple clean JavaScript for you purpose.

<script>
function validate(){
if(!document.getElementById("AcceptTerms").checked)
    alert("You should accept terms in order to proceed!");
else
    alert("Proceed.");
}
</script>
<html>
<label for="AcceptTerms">Accept Terms</label>
<input class="required" id="AcceptTerms" name="AcceptTerms" type="checkbox" aria-required="true"/>
<input type="button" value="Submit" onclick="validate();"/>
</html>

8 Comments

correct! but that's not my issue, i asked whey is it not displaying my custom message
Because the form is not getting submitted. I have added the code to my answer. Try it.
i'm still not getting my custom message
Did you removed the aria-required="true"?
well did you try it before you posted this? do you know what aria-required="true" does?
|

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.