I just started working with the jquery validate plugin, but could not get it to work properly.
I have an example on Fiddle located at http://jsfiddle.net/GWABv/3/
Can someone tell me what the hell am I doing wrong? I'm just trying to require the user to select a parameter from the drop-down list, but even when I do not select a value, it returns, saying that the form is valid.
HTML:
<form id="roadForm" method="get" action=""> <p> <label for="editRoad_ProjectClassification"> <em class="red">*</em> Project Classification: </label> <select id="editRoad_ProjectClassification" name="editRoad_ProjectClassification" title="Please select something!" validate="required:true"> <option value="">Please select</option> <option value="1">1</option> <option value="2">2</option> </select> </p> </form> <label class="FUNC_saveRecord"> <span class="icon iconSave"></span> <span class="title">Save</span> </label>
JavaScript:
$('.FUNC_saveRecord').click(function() { saveRecord(); }); function saveRecord() { var roadFormValidator = $('#roadForm').validate(); if (!roadFormValidator.valid()) { roadFormValidator.showErrors(); } else { alert('form is valid'); } }
source share