Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>First, I would <em>not</em> use spaces in your input names, as then you have to deal with weird escaping issues. Use something like "QuantityAndDescription" instead.</p> <p>Also, it looks like you're trying to have multiple fields with the same name. The best way to do that is to add brackets to the name, meaning the values will be grouped together as an array:</p> <pre><code>&lt;textarea name="QuantityAndDescription[]"&gt;&lt;/textarea&gt; </code></pre> <p>This also means the code has to get all the textareas, not just the first. We can use jQuery to grab the elements we want, to loop over them, and to check the values. Try this:</p> <pre><code>function checkform() { var success = true; // Find the textareas inside id of "comform", store in jQuery object var $textareas = $("form#comform textarea[name='QuantityAndDescription[]']"); // Loop through textareas and look for empty values $textareas.each(function(n, element) { // Make a new jQuery object for the textarea we're looking at var $textarea = $(element); // Check value (an empty string will evaluate to false) if( ! $textarea.val() ) { success = false; return false; // break out of the loop, one empty field is all we need } }); if(!success) { alert("Quantity &amp; Description must be filled out, DO NOT just put an SO#!!"); return false; } // Explicitly return true, to make sure the form still submits return true; } </code></pre> <p>Also, a sidenote of pure aesthetics: You no longer need to use the CDATA comment hack. That's a holdover from the old XHTML days to prevent strict XML parsers from breaking. Unless you're using an XHTML Strict Doctype (and you shouldn't), you definitely don't need it.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload