Greetings y'all,
I'm looking to dynamically turn on/off a couple requiredfieldvalidator controls - the easiest way possible.
I have a dropdownlist and some textbox controls:
And the DDL fires fires some javascript to show/hide textbox fields:
Not exactly radical new therapy in web design. What I want is to add a requiredfieldvalidator to the two textboxes if they're visible.
Thought about a custom field validator, but that might be overcomplicating the obvious.
Any help is appreciated. I am using ASP/VB 2.0
"If it's stupid but works, it isn't stupid."
-Murphy's Military Laws
I'm looking to dynamically turn on/off a couple requiredfieldvalidator controls - the easiest way possible.
I have a dropdownlist and some textbox controls:
Code:
<li><label for="ddlRepeats">Repeating</label>
<asp:DropDownList ID="ddlRepeats" runat="server">
<asp:ListItem Value="1" Selected="True">Does Not Repeat</asp:ListItem>
<asp:ListItem Value="2" Selected="False">Same Day of the Month</asp:ListItem>
<asp:ListItem Value="3" Selected="False">Every ___ Days</asp:ListItem>
</asp:DropdownList>
</li>
<li id="repeatfield1" style="display:none;"><label for="txtRepeatDay" id="lblRepeatDay">Day to Repeat On</label><asp:TextBox ID="txtRepeatDay" MaxLength="2" Size="5" runat="server" /></li>
<li id="repeatfield2" style="display:none;"><label for="txtRepeatNo">No. of Repeats</label><asp:TextBox ID="txtRepeatNo" MaxLength="3" Size="5" runat="server" /></li>
Code:
<script language="javascript">
function toggle_repeat_fields(fld) {
if(fld.value == 1) {
document.getElementById('repeatfield1').style.display = 'none';
document.getElementById('repeatfield2').style.display = 'none';
} else {
document.getElementById('repeatfield1').style.display = 'block';
document.getElementById('repeatfield2').style.display = 'block';
}
if(fld.value == 2) {
document.getElementById('lblRepeatDay').innerHTML = "Day to Repeat On";
} else {
document.getElementById('lblRepeatDay').innerHTML = "Day Interval";
}
}
</script>
Thought about a custom field validator, but that might be overcomplicating the obvious.
Any help is appreciated. I am using ASP/VB 2.0
"If it's stupid but works, it isn't stupid."
-Murphy's Military Laws