0

I have got a problem when trying to identify an INPUT with empty value or which has got just value attribute without ="". Please see below my code.

<form id='form'>
<div class='input-field col s12'>
    <input id='title' type='text' value>
    <label for='title'>Job Tilte</label>
</div>
<div class='input-field col s12'>
    <input type='text' id='company' value='test' />
    <label for='company'>Company Name</label>
</div>
<div class='input-field col s12'>
    <input type='text' id='telephone' value='' />
    <label for='telephone'>Telephone Number</label>
</div>
<div class='input-field col s12'>
    <textarea id='description' placeholder='test2'></textarea>
    <label for='description'>About you</label>
</div>
<div class='input-field col s12'>
    <input type='password' id='password' />
    <label for='password'>Your password</label>
</div>
<div class='input-field col s12'>
    <input type='password' id='re-password' />
    <label for='re-password'>Confirm your password</label>
</div>
<input type='submit' disabled='disabled' value='Update' id='sendbutton' />

And this is my jQuery:

if ($('#form input').val().length !== 0 ) {
        $(this).hide();
        } else {
        $(this).next().addClass('active');
        }

Could anybody help me with this issue? Many thanks in advance.

2 Answers 2

1

use below code . each() you can get all the inputs elements inside #form . see DEMO

  $(document).ready(function(){
   $('#form input').each(function(){
     if ($(this).val().length !== 0 ) {
        $(this).hide();
     } else {
       $(this).next().addClass('active');
     }
  });
 });
Sign up to request clarification or add additional context in comments.

Comments

1

You need

$('#form input').each(function () {
    if (this.value.length !== 0) {
        $(this).hide();
    } else {
        $(this).next().addClass('active');
    }
})

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.