Bassistance validation plugin
Thanks in advance for your help!
I have a form which successfully uses the
bassistance validation plugin to highlight required fields.
Currently all fields with class="required error" are set to always flag as required if no data entered (mainly textarea fields)
The requirement now is for some questions which have a yes/no radio button. If user selects Yes the textarea asking for more information needs to be available and a required field, if user selects No this is not required.
Having scoured around the web I have come up with the following:
HTML CODE:
- <form onsubmit="return submitIt3(this)" action="step-2" method="post" name="form1" id="form1" novalidate="novalidate">
- <ol>
- <li>
- <span class="form-title"><strong>Question 1</strong></span><br>
- <input type="radio" name="screen_184" value="Yes" checked>
- <label>Yes</label>
- <input type="radio" name="screen_184" value="No">
- <label>No</label>
- <br><br>
- <textarea class="required error" maxlegth="500" name="screentext_184"/></textarea></li>
- <label for="screentext_184" generated="true" class="error">This field is required.</label>
- </li>
- <br><br>
- <a href="javascript:history.back()">
- <img class="button" src="img/back.jpg" height="30" width="72"></a>
- <img src="img/peaks.jpg" class="peaks">
- <input class="button" name="next-button" value="submit" type="image" src="img/next.jpg" height="30" width="72">
-
- </ol>
- </form>
I need to know how/where to edit the code in js to get this working.
Where/how should i add this code in the jquery.validate.js file
JS CODE:
- $(document).ready(function () {
- $('#form1').validate({ // initialize the plugin
- rules: {
- "screentext_184": {
- required: {
- depends: function (element) {
- return $("input[name='screen_184'][value='Yes']").is(":checked");
- }
- }
- }
- },
- submitHandler: function (form) {
- alert('valid form submitted');
- return false;
- }
- });
- });
Thanks again