Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You are replacing x every time you say <code>var x=someField</code>. What you want to do is assign each to a new variable then check all of them. You can do this with an array. Try something like this. </p> <pre><code>function validateForm(){ var x = new Array(); x.push(document.forms["jobapp"]["lastname"].value); x.push(document.forms["jobapp"]["address"].value); x.push(document.forms["jobapp"]["city"].value); x.push(document.forms["jobapp"]["planet"].value); x.push(document.forms["jobapp"]["system"].value); x.push(document.forms["jobapp"]["cluster"].value); x.push(document.forms["jobapp"]["phone"].value); x.push(document.forms["jobapp"]["email"].value); x.push(document.forms["jobapp"]["resume"].value); for(var i = 0; i &lt; x.length; i++){ if (x[i]==null || x[i]==""){ alert("All fields must be filled in"); return false; } } } </code></pre> <p>The above code will alert once for every field that you left empty so it isn't the best but it fixes your issue.</p> <p>You may want to set a bool if a field is empty and alert once we have tested every field:</p> <pre><code>var fieldIsEmpty = false; for(var i = 0; i &lt; x.length; i++){ if (x[i]==null || x[i]==""){ fieldIsEmpty = true; } } if(fieldIsEmpty) { alert("All fields must be filled in"); return false; } </code></pre> <p>Also, alert can get really annoying. For instance if you left every field empty with the first code above. <code>console.log("All fields must be filled in")</code> would be nice for testing.</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