I have a date picker on one of my pages, and it has a text box, a button to click to view the calendar, and a submit button. When I click the button to view the calendar, I can pick the date and it shows up in the text box. However, I'd like to also be able to click inside the box to view the calendar, but currently nothing happens when I click in the box. Here is the code (currently in the head section but I plan to make it external later):
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js" type="text/javascript"></script>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="Stylesheet" type="text/css" />
<script type="text/javascript">
$(function () {
$("[id$=TextBox1]").datepicker({
showOn: 'button',
buttonImageOnly: true,
buttonImage: 'http://jqueryui.com/demos/datepicker/images/calendar.gif'
});
});
</script>
And here is the textbox:
<asp:TextBox ID="TextBox1" runat="server" ReadOnly="true"></asp:TextBox>
<asp:Button ID="btnSave" runat="server" Text="Edit Comments" OnClick="editComments_Click" />
Does anyone know how to make it so the calendar shows up when I click in the box? I don't want to be able to type the date in manually, but I would like to be able to click the textbox instead of the button. In fact, if possible I'd like to be able to get rid of the button and just click in the box. Thanks!
Figured it out, but I'll leave the question up in case anyone else comes across this problem. All you have to do is change showOn: 'button'
to showOn: 'focus'
, and then the button disappears and you just click the text box to see the calendar. If you want to be able to click either the button or text box, use showOn: 'both'
.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments