1

I'm validating forms with Javascript, 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!

3 Answers 3

2

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 = ...).

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

1 Comment

This is indeed the most simple way.. it's also possible to create the div on the fly and place it near the textbox. :)
1

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).

Comments

0

Are you using jQuery?

If you you can use something like this:

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

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.