Hi all,
I have a select (combobox) like this:

<select name="role" id="role">
      <option value="Admin">ADMIN</option>
      <option value="User">User</option>
      <option value="Other" id="Other">OTHER (specify)</option>
</select>

and a textbox like:

<input name="txtOther" id="txtOther" type="text" />

I'd like to validate the textbox if the selected choice is 'Other'.

I'm trying this code:

$(document).ready(function() {
        $('#txtOther').hide();

        $('#role').change(function() {
            var itemValue = $(this).val();
            //alert('ItemValue: ' + itemValue);
            if (itemValue == 'Other') {
                //alert('True');
                $('#txtOther').show();
            }
            else {
                //alert('False');
                $('#txtOther').hide();
                $('#txtOther').validate(false);
            }
        });
    });


$(document).ready(function() {
        $("form#myform").validate({
            rules: {
                role: {
                    required: true
                },
                other: {
                    required: true
                }
            },
            messages: {
                ruolo: {
                    required: "<span style='color:#ff0000;'>*</span>"
                },
                altro: {
                    required: "<span style='color:#ff0000;'>Specify
\'Other\'</span>"
                }
            }
        });
    });


but does not work, because the validation error message (Specify
'Other') always appears.

Has anyone ideas?

Thanks

Luis

Reply via email to