How do I launch datepicker from a textbox based on the drop down item chosen?
I am working in ASP.NET 4.0 and use IE8, Firefox and Chrome for testing. Inside the web page I have a textbox and a drop down with 5 items. If the 4th item is chosen I want the textbox to become a datepicker.
Here is my best attempt thus far. Any help or advice is greatly appreciated.
$(document).ready(
function
() {
$(
"#txtSearch"
).focus(
function
() {
if
($(
"#ddlSearch"
).attr(
"selectedindex"
) == 4) {
$(
"#txtSearch"
).datepick(
"enable"
);
}
else
{
$(
"#txtSearch"
).datepick(
"disable"
)
}
});
});
<
link href="Styles/jquery.datepick.css" rel="stylesheet" type="text/css" />
<
table width="100%" align="center">
<tr height="32px">
<td>
<asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>
</td>
<td>
<asp:DropDownList ID="ddlSearch" runat="server" AutoPostBack="False">
<asp:ListItem Selected="False" Value="1">option1</asp:ListItem>
<asp:ListItem Selected="False" Value="2">option2</asp:ListItem>
<asp:ListItem Selected="False" Value="3">option3</asp:ListItem>
<asp:ListItem Selected="True" Value="4">option4</asp:ListItem>
<asp:ListItem Selected="False" Value="6">option5</asp:ListItem>
</asp:DropDownList>
</td>
<td align="left" width="100%">
<asp:LinkButton ID="cmdSearch" runat="server" CssClass="BUTTONIMAGE">Search</asp:LinkButton>
</td>
</tr>
</table>