Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

TD Input check

Featured Replies

Trying to get this script to do this:

 

if any of the td text inputs are empty in this tr

do this

else

so something else.

 

My Table

    <table id="project">
        <tbody>
          <tr>
            <td><input type="button" value="×" class="delete"></td>
            <td><input type="button" value="∧" class="move up" ></td>
            <td><input type="button" value="∨" class="move down"></td>
            <td><input name="data[0][0]" data-field="description" placeholder="Description" required size="40"></td>
            <td><input name="data[0][1]" data-field="quantity" placeholder="Q" size="1" required></td>
            <td><input name="data[0][2]" data-field="price" placeholder="P" size="7" required></td>
            <td><input name="data[0][3]" data-field="total" placeholder="T" size="7" readonly required></td>
            <td><input type="button" value="&plus;" class="add"></td>
          </tr>
        </tbody>
      </table>

My JS

if ($('input:text').val().length == 0) {
alert("empty")
}else{
alert("Not empty")
}

This kind of works, if I use this it will display "empty" if they are all empty, but if i input text into just one of them then it goes to the else.

 

Anyone know how this could work?

$.val() when applied to a collection will only return the value of the first element.

 

To check all the values you'll have to iterate through each input or filter them.

if ($('input:text').filter(function() {
    return this.value.trim() === "";
  }).length > 0) {
  alert("empty")
} else {
  alert("Not empty")
}

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.