开发者

How do I display error text via Javascript?

开发者 https://www.devze.com 2023-02-14 00:27 出处:网络
I\'m validating forms with Java开发者_StackOverflow社区script, and I found out how to switch borders/backgrounds of input fields if there is an error, but I want to display text next to the box.How wo

I'm validating forms with Java开发者_StackOverflow社区script, and I found out how to switch borders/backgrounds of input fields if there is an error, but I want to display text next to the box. How would I do that? Thanks!


Create a div object next to the respective box, give it a certain width in its style attribute to make it visible, and then find it in javascript by using the DOM or just getElementById(...), and modify its innerHTML by using js. (as in, myDiv.innerHTML = ...).


If you use the jQuery Validate plugin this could be handled for you. Here's an example http://docs.jquery.com/Plugins/validation#Example (just push the Submit button).


Are you using jQuery?

If you you can use something like this:

jQueryElement.addClass('error').after('<span class="errorMessage">error message here</span>');
0

精彩评论

暂无评论...
验证码 换一张
取 消