 <p>If <code>"formname"</code> is the value of the name attribute of the form and <code>"name"</code> is the value of the name attribute of the input field (as per your example):</p> <pre><code>if( document.forms["formname"].elements["name"].value == "" ){ // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ document.getElementById("namef").innerHTML = "Please imput name"; return false; } </code></pre>