I am using jQuery validation plugin ( http://bassistance.de/jquery-plugins/jquery-plugin-validation/ )
I have following structure:
<select name="s1" id="s1">
<option value="url">url</option>
<option value="normal">normal</option>
</select>
<input name="s1_value" id="s1_value" type="text" />
Now, I need validation rule (using jQuery validation plugin) as
If I select ‘url’ as value in list box, then input field should only contain valid URL
If I select ‘normal’ as value in list box, then input field can contain any text
For any selection, value for input field should not be empty
How to do this?
The validation plugin allows rules to be specified in each element’s class. You can start with the
requiredandurlrules:From there, you can remove the
urlclass if the list box value becomesnormal:That way, the validation plugin won’t validate the field against the
urlrule, since it does not expose that rule in its class.You can test this solution here.