Using jQuery to populate ValidatorHookupControl

zRANDOMz

New Member
I have the following form items:\[code\]Medications: <asp:RadioButtonList ID="meds" runat="server" RepeatDirection="Horizontal"> <asp:ListItem Value="http://stackoverflow.com/questions/15887800/1">Yes (list below)</asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15887800/0">No</asp:ListItem></asp:RadioButtonList>Medication List:<asp:CustomValidator ID="val_medsList" runat="server" ClientValidationFunction="check_medsList" OnServerValidate="val_medsList_ServerValidate" ValidationGroup="GroupSave" ValidateEmptyText="true" ErrorMessage="required" ControlToValidate="medsList" EnableClientScript="true"></asp:CustomValidator><br /><asp:TextBox ID="medsList" CssClass="jQueryMedsListTarget" TextMode="MultiLine" runat="server" Width="500" MaxLength="500" Wrap="true" Rows="3" />\[/code\]The idea is if "Yes" is selected the textbox needs to be filled out and the opposite is true if "No" is selected. In order to have the "Yes"/"No" options trigger the custom validator I use 'ValidatorHookupControl' as such:\[code\]ValidatorHookupControl(document.getElementById('meds_0'), document.getElementById('val_medsList'));ValidatorHookupControl(document.getElementById('meds_1'), document.getElementById('val_medsList'));\[/code\]This works for me, but this will become annoying when I have more than two options. I created the following to loop through all of the options but it doesn't seem to work ("yes" and "no" do not trigger the custom validator):\[code\]$(document).ready(function () { hookupRadioButtonListToVal($('input[id^=meds_]'), $('#val_medsList'));}); function hookupRadioButtonListToVal(rbl, validator) { $(rbl).each(function () { ValidatorHookupControl($(this), $(validator)); });} \[/code\]I assume I am not returning the correct type of element with \[code\]$(this)\[/code\] and \[code\]$(validator)\[/code\] but not sure where to go from there.
 
Back
Top