title: Javascript multiple alerts for multiple fields
body: <p>I’m working on a function where I’m gonna check numerous input fields with regexes. However, instead of letting it return false for each of the ”ifs” I’d like it to go through all of the conditions, and then output all of the innerHTMLs at once, from different conditions and input boxes. The text appears under each of the boxes. To give you a hint of what I'm going for.</p>
  
  <p>Instead of having to input something to one box, for getting an error - correcting it, then getting a new error for the next box in the form. I'd like to see that all errors occur on the same button click. (the function trigger from a button).</p>
  
  <p>The code below does not show the errors simultaneously. Is there any way to perform this without a loop? It feels like it should be, but I'm not sure how to move on.</p>
  
  <pre><code> function sum()
        {
            prem1 = document.formular.Uppgift1.value;
            prem2 = document.formular.Uppgift2.value;
            prem3 = document.formular.Uppgift3.value;
            prem4 = document.formular.Uppgift4.value;
            totpr = document.formular.priset.value;
  
  
            varning1 = "name";
            varning2 = "address";
            varning3 = "phone";
            varning4 = "phone number has to contain numbers";
            varning5 = "e-mail";
            varning6 = " - This one is not relevant to the input fields and should only show when thus are correct - ";
  
  
  
            var re = /^[\w ]+$/;
  
  
              if(!re.test(prem1)) {
              document.getElementById('texterror1').innerHTML = (varning1);
              form.inputfield.focus();
               return false;
               }
  
               if(!re.test(prem2)) {
              document.getElementById('texterror2').innerHTML = (varning2);
              form.inputfield.focus();
               return false;
               }
  
               if(!re.test(prem3)) {
              document.getElementById('texterror3').innerHTML = (varning3);
              form.inputfield.focus();
               return false;
               }
  
               var re = /^(?=.*[0-9])\w{1,}$/;
  
               if(!re.test(prem3)) {
              document.getElementById('texterror4').innerHTML = (varning4);
              form.inputfield.focus();
               return false;
               }
  
               if(!re.test(totpr)) {
              alert (varning6);
              form.inputfield.focus();
               return false;
               }
  
               var re = /^[\w ]+$/;
  
               if(!re.test(prem4)) {
              document.getElementById('texterror5').innerHTML = (varning5);
              form.inputfield.focus();
               return false;
               }
  
            else (alert ("Tack för din beställning " +prem1 + "! Här följer de uppgifter vi mottagit om dig. Adress: " +prem2 +" Tel.nr: " +prem3 +" E-post: " +prem4 +" Pris att betala: "  +Discount +" kr" ));{
            return true;
           }
        }
  </code></pre>
  
  <p><em>The code was translated on the relevant parts</em></p>