Check if a form control is empty - Node.js HTML

Node.js examples for HTML:Form

Description

Check if a form control is empty

Demo Code

  isEmpty : function(s) {
    var nl, i;//from w ww.  j  a v a 2  s  .  c  o m

    if (s.nodeName == 'SELECT' && s.selectedIndex < 1)
      return true;

    if (s.type == 'checkbox' && !s.checked)
      return true;

    if (s.type == 'radio') {
      for (i=0, nl = s.form.elements; i<nl.length; i++) {
        if (nl[i].type == "radio" && nl[i].name == s.name && nl[i].checked)
          return false;
      }

      return true;
    }

    return new RegExp('^\\s*$').test(s.nodeType == 1 ? s.value : s);
  }

Related Tutorials