Is there开发者_C百科 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
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 ?
精彩评论