Reputation: 1335
I am new to jquery, How do we make the date to appear in the textbox on the click of an button using jquery and ASP.NET? The calendar apears but it disappears very fast works fine with a textbox? What else do i need to include in the script of my button? I have used this function
<script type="text/javascript" language="javascript">
$(document).ready(dateselect)
function dateselect()
{
var date1 = $("#Button1").datepicker();
}
</script>
<asp:Button ID="Button1" runat="server" Text="Button" />
Upvotes: 1
Views: 4408
Reputation: 17614
Javascript:
<script type="text/javascript">
$(function() {
$("#<%= txtFrom.ClientID %>").datepicker({
showmonth:true,
autoSize: true,
showAnim: 'slideDown',
duration: 'fast'
});
$("#<%= ImageButton1.ClientID %>").click(function() {
$("#<%= txtFrom.ClientID %>").datepicker('show');
});
});
</script>
Code:
<asp:TextBox ID="txtFrom" MaxLength="10" runat="server" ToolTip="Enter From Date">
</asp:TextBox>
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/Images/clock_add.gif" />
Reference jquery forum
Change this function
$("#<%= ImageButton1.ClientID %>").click(function() {
$("#<%= txtFrom.ClientID %>").datepicker('show');
});
to
$("#<%= ImageButton1.ClientID %>").click(function() {
$("#<%= txtFrom.ClientID %>").datepicker('show');
return false;
});
or
$("#<%= ImageButton1.ClientID %>").click(function(event) {
$("#<%= txtFrom.ClientID %>").datepicker('show');
event.preventDefault();
});
$("#txtStartDate").datepicker({
showOn: "both",
onSelect: function(dateText, inst){
$("#txtEndDate").datepicker("option","minDate",
$("#txtStartDate").datepicker("getDate"));
}
});
Source :
Restrict date in jquery datepicker based on another datepicker or textbox
Upvotes: 1
Reputation: 3225
Try this
<script type="text/javascript">
$(document).ready(function() {
$("#txtDate").datepicker({
showOn: 'button',
buttonText: 'Show Date',
buttonImageOnly: true,
buttonImage: 'http://jqueryui.com/demos/datepicker/images/calendar.gif'
});
});
</script>
<input type='text' id='txtDate' />
It works fine i had tried this
Upvotes: 0