title: How do I determine if form field is empty with jQuery?
body: <p>I've got a form with two fields, firstname and lastname.  The user does not have to fill in the fields.  When the user clicks the submit button, a jquery dialog displays with the data the user entered in the form.  I only want to show the data for the fields that were entered. I'm trying to do an if statement and use the length() function but it isn't working.  Help would be great!</p>
  
  <p>Here is my dialog jquery script:</p>
  
  <pre><code>$(function(){
      //Initialize the validation dialog
      $('#validation_dialog').dialog({
          autoOpen: false,
          height: 600,
          width: 600,
          modal: true,
          resizable: false,
          buttons: {
              "Submit Form": function() {
                  document.account.submit();
              },
              "Cancel": function() {
                  $(this).dialog("close");
              }
          }
      });
      // Populate the dialog with form data
      $('form#account').submit(function(){
          $("p#dialog-data").append('&lt;span&gt;First Name: &lt;/span&gt;');
          $("p#dialog-data").append('&lt;span&gt;');
          $("p#dialog-data").append($("input#firstname").val());
          $("p#dialog-data").append('&lt;/span&gt;&lt;br/&gt;');
          if (("input#lastname").val().length) &gt; 0) {
              $("p#dialog-data").append('&lt;span&gt;Last Name: &lt;/span&gt;');
              $("p#dialog-data").append('&lt;span&gt;');
              $("p#dialog-data").append($("input#lastname").val());
              $("p#dialog-data").append('&lt;/span&gt;&lt;br/&gt;');
          };
          $('#validation_dialog').dialog('open');
          return false;
      });
  });
  </code></pre>