0

Could you suggest how to show the error message not after element with id #genderError but insert it inside?

errorPlacement: function(error, element) {
    if (element.attr("name") == "myoptions" ) error.insertAfter('#genderError'); 
    },    
1
  • use $('#genderError').append(error) to add it to the end of the element or $('#genderError').prepend(error) to add it to the start. or $('#genderError').html(error) to swap the inner HTML of the element with the content of error. But this should be googled, not asked here. insert jquery gives you something lik 3 mil posts Commented Mar 12, 2020 at 11:35

3 Answers 3

1
document.getElementById('#genderError').innerHTML = error; 

Or if you're using jQuery:

$('#genderError').html(error);

or

$('#genderError').text(error);`

if you just need to set the text.

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

Comments

0

You can manage multiple conditions inside errorPlacement.

Like below -

errorPlacement: function(error, element) {
            if (element.attr("name") == "genderError") {
                $('#genderError').html(error); //or
                //$('#genderError').after(error);
            }
            else {
                if (element.hasClass("chosen-select")) {
                    error.insertAfter(element.next('div.chosen-container'));         
                }
                else {
                    error.insertAfter(element);  
                }
            }
        }

1 Comment

@Dimtriy, Thanks for approving my answer.
0

May i introduce a CSS form validation as a workaround solution?

<form>
  <label for="male">male</label>
  <input type="radio" name="gender" value="male" id="male" required>
  <label for="female">female</label>
  <input type="radio" id="female" name="gender" value="male" required>
  <span class="errMsg"></span>
</form>

input:invalid ~ .errMsg::after {
  content: '\2717';
  color: red;
}

input:valid ~ .errMsg::after {
  content: '\2713';
  color: green;
}

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.