JavaScript JQuery Check if input is empty on page load jquery check input value,jquery check input type,jquery check

Hey I have a login form that when you click on the input the label move up, after focus out it checks if there is text in the input and if have the label stays up if dont the label comes down.

My code is:

$(function () {
    $('.loginForm .inputGroup input').focusout(function () {
        var text_val = $(this).val();
        if (text_val === "") {
            $(this).removeClass('has-value');
        } else {
            $(this).addClass('has-value');
        }
    });
});

The problem is when I click on login and it gives an error like username does not exist I want to keep the username on the input but when I do it the label stays on top of the text on the input.
How can I check on load if have text or not on the input?

Images to help understand the situation:

enter image description here enter image description here

JSFiddle: http://jsfiddle.net/16g7yhLf/

Cheers!

Answer:1

I am creating a custom carousel and its working fine. What I have:- I have a basic code which is working fine and carousel is also working fine in all screen and devices. What I Want:- I have to ...

I am creating a custom carousel and its working fine. What I have:- I have a basic code which is working fine and carousel is also working fine in all screen and devices. What I Want:- I have to ...

  1. bind resize event to div
  2. jquery bind resize event
  3. angular bind resize event
  4. bind window resize event
  5. jquery bind resize event div
  6. angularjs bind resize event

I have a content DIV with many paragraphs. This is how its' markup look, <div class="more"> <p>Based on a study of its skull, scientists say that an extinct one-tonne relative of ...

I have a content DIV with many paragraphs. This is how its' markup look, <div class="more"> <p>Based on a study of its skull, scientists say that an extinct one-tonne relative of ...

I would like to make a chrome extension that simply serve static content from a defined directory. As usual the static directory will be in the extension repository. I would like the extension to ...

I would like to make a chrome extension that simply serve static content from a defined directory. As usual the static directory will be in the extension repository. I would like the extension to ...

  1. chrome extension static id

I'm trying to make a GET request through jQuery to the Mailchimp API. It seems though my custom header is not correctly set as I get a Your request did not include an API key. error. It works fine if ...

I'm trying to make a GET request through jQuery to the Mailchimp API. It seems though my custom header is not correctly set as I get a Your request did not include an API key. error. It works fine if ...