There are several libraries & native APIS to handle client side validation that are worth leveraging
You can use the required
attribute in any input and the browser will block client side submits:
<!-- language: lang-html -->
<pre><code><input id="name" name="name" <b><i>required</i></b> ></code></pre>
For more advanced handling, you can also wire up Javascript using the Constraint Validation API
jQuery Validate
Another popular client side validation framework is the jQuery Validation Plugin
Custom JavaScript
If you want to write yourself... assuming all fields are required, you'll need to capture change events to all inputs, verify that all inputs have a value, and then conditionally toggle the disabled attribute on the submit button. In jQuery, it would look something like this:
<!-- language: lang-js -->
// get all input elements and attach listener
var $inputs = $("#myForm :input:not([type='submit'])")
$inputs.change(function() {
// check if all elements have value
var allInputsHaveValue = $inputs.toArray().every(function(el) {
return !!el.value
});
// toggle submit disabled
$("#submit").prop("disabled", !allInputsHaveValue);
}).change(); // run on init
Demo in jsFiddle