I wrote validation code for a form, which goes:
function checkWholeForm(theForm) {
  // Create validation variables
  var valid = true;
  var validationMessage = "Please correct the following errors: \r\n";
  // Validate name
  if (document.getElementById('name').value.length == 0)
        {
            validationMessage = validationMessage + '  - Name is missing\r\n';
            valid = false;
        }
//(and there's a few other functions)
// Display alert box with errors if any errors found
  if (valid == false)
        {
            alert(validationMessage);
        }
        return valid;
  }
and then in the HTML page, it goes:
<form action="submit.php" method="post" enctype="text/plain" onsubmit="return checkWholeForm(this)">
and in the table is:
<input type="text" id="name" name="name" size="20" value="" />
But when I hit submit, an empty text box doesn't trigger the alert. What am I doing wrong?
Edit: http://jsbin.com/uvepin/2/edit for the full HTML and JS.
validationMessage = validationMessage + ' - Name is missing\r\n';should have double quotes if you want to add a\ror a\n. This is not the reason your script doesn't work. Please use pastebin or paste the complete script here.validMessagewhen it should bevalidationMessage. And please don't use patsebin.com, use jsfiddle.net or jsbin.com so that you can also include your html/css and we can actually run your code.'\r\n'is perfectly valid JS. You don't need double-quotes.