-4

I am trying to build a simple login form with HTML and CSS and I am using Javascript for empty field validations.

Here is my jsfiddle

I am trying to validate for empty text on the textboxes and display the error message below each textbox using the css and HTML.

CSS

.validation
{
  color: red;
  margin-bottom: 20px;
}

Javascript

$("#txtUsername").parent().after("<div class='validation' style='color:red;margin-bottom: 20px;'>Please enter username</div>");

I am trying to follow this question and replicate same but somehow it it not working.

Any help?

Thanks in advance.

3
  • 1
    What exactly is not working? What functionality are you trying to replicate and which part doesn't work? Commented Oct 23, 2017 at 3:02
  • 2
    Define "not working". What errors do you get? Please post a minimal reproducible example in your question and properly tag it (it appears as if you're using jQuery but the tag is missing) Commented Oct 23, 2017 at 3:02
  • Not working the validation.If you would have opened jsfiddle, I am sure you noticed it.Thanks for your time Commented Oct 23, 2017 at 3:15

1 Answer 1

1

In your JSFiddle, jQuery is not added as a library. Thus your jQuery validation code is not being called.

It works if you add jQuery.

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

2 Comments

Oh, I didn't know this..Thanks much
@Santosh You're welcome! Please make sure to mark this answer as accepted to show the community it helped you.

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.