carbonr
carbonr

Reputation: 6067

.children .val() is throwing undefined

I'm trying to form validation but .val() seems to be giving undefined.

$(document).ready( function() {

  $('.formElem .input').each(function() {    
    $(this).children(".inputField").on("keyup", function() {

      console.log($(this).children('#username').val());

    });
  });
});

This is the html part

<form action="#" class="formElem" method="post" autocomplete="off">
 <div class="input username_container">
        <input class="inputField" id="username" maxlength="50" placeholder="Username" name="username" size="20" tabindex="1" type="text">               
        <div class="tip">
          <p class="blank error">Field cannot be empty</p>
     </div>
  </div>

Upvotes: 0

Views: 1893

Answers (2)

carbonr
carbonr

Reputation: 6067

This was a dumb ass question. Only posted due to fact that i didn't know how to search it. But thanks to @Juhana for the answer

$(this).val();

Upvotes: 0

Patrick Moore
Patrick Moore

Reputation: 13344

'username' is not a valid parameter to pass to .children()

input would work if you're targeting an input field, as would .username if you have a class specified on the child.

Upvotes: 3

Related Questions