0

Is there any way to show custom input validation message through javascript? I have javascript validation method innvoked with Form.Submit, so if validation goes wrong, I'd like to have a custom text next to the field I have validated (similar as ASP.NET MVC 2 validation summary).

Regards

1 Answer 1

1

Yes, you can. Just create a <span> after every field, do the validation in javascript, and populate this field with the error message when validation fails.

<script>
   function validate()
   {
      if(document.getElementById('txtName').value="")
      {
         document.getElementById('errName').innerHTML = 'Please enter your name';
      }
   }
</script>

<form onsubmit=validate()>
   <input type="text" id="txtName" name="txtName"/>
   <span name="errName" class="error" />
</form>

Isn't this what you are looking at ?

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.