[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 480
  • Last Modified:

jquery data picker

dear experts,
I wanted button to display with my date and when the button is clicked the jquery calendar pops up initialized with the date on the button. When the calendar is clicked the button updates with the picked date.

Not sure how to do it. Please help. thanks a lot

<%@ Page Language="C#" AutoEventWireup="true" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <title></title>

  <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" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
  <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
 
  <script type="text/javascript" >
      $(document).ready(function() {
          $("#datepicker").datepicker();
      });
  </script>
</head>
<body>
<form runat="server">    
<asp:Button ID="datepicker" runat="server" Text="Button" />


</form>
 
</body>
</html>
0
goodk
Asked:
goodk
2 Solutions
 
Lukasz ChmielewskiCommented:
I do not know much about asp but it seems that datepicker is designed for input fields of text type. Not sure it this would work, but you could do a hidden text field and update the button with it's value.
0
 
goodkAuthor Commented:
can you show in javascript html, how would you code it? I can follow. thanks
0
 
Roman GhermanCommented:
Hi,

Why are you using a button?

You need to use a textbox instead.

jQuery.datepicker, supports icon trigger, if you need an icon for triggering the date picker:

<script>
	$(function() {
		$( "#datepicker" ).datepicker();
	});
	</script>



<div class="demo">

<p>Date: <input type="text" id="datepicker"></p>

</div><!-- End demo -->

Open in new window


See more details on jquey ui page: http://jqueryui.com/demos/datepicker/#icon-trigger

--------------------------
You can find my on - Development Solutions: www.extremedev.blogspot.com
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
goodkAuthor Commented:
thanks, but I really do not want the date to be editable - only should be able to pick from the calendar. thanks
0
 
SAMIR BHOGAYTAFreelancer and IT ConsultantCommented:
Hi, use the following example

Page sourcecode

$(function()
{
      $('.date-pick').datePicker({clickInput:true})
});

Page CSS

/* located in demo.css and creates a little calendar icon
 * instead of a text link for "Choose date"
 */
a.dp-choose-date {
      float: left;
      width: 16px;
      height: 16px;
      padding: 0;
      margin: 5px 3px 0;
      display: block;
      text-indent: -2000px;
      overflow: hidden;
      background: url(calendar.png) no-repeat;
}
a.dp-choose-date.dp-disabled {
      background-position: 0 -20px;
      cursor: default;
}
/* makes the input field shorter once the date picker code
 * has run (to allow space for the calendar icon
 */
input.dp-applied {
      width: 140px;
      float: left;
}

more on this

http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/datePickerClickInput.html
0
 
Roman GhermanCommented:
Ok,
Try this then - it works for me:
<html>
<head>
  <script src="http://code.jquery.com/jquery-1.4.4.js"></script> 
  <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js"></script> 
<script language="JavaScript"> 
$(document).ready(function(){
    $( "#t" ).datepicker();
});
</script>
</head>
 
<body>
	<input type='button' id ='t' value='Show Calendar' onclick='$( "#t" ).datepicker( "show");'/>
</body>
</html>

Open in new window


------------------------
You can find me on: www.extremedev.blogspot.com
0
 
goodkAuthor Commented:
wow, works like a charm - but the css look is not same
I created the new css file with code like samirbhogayta: has

<html>
<head>
    <title></title>
   
    <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css"
        rel="stylesheet" type="text/css" />
    <link href="../jquery/Calendar.css" rel="stylesheet" type="text/css" />   /*like samirbhogayta: has

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>

    <script type="text/javascript">
        $(document).ready(function() {
            $("#datepicker").datepicker();
        });

        $(document).ready(function() {
            $("#t").datepicker();
        });
    </script>

</head>
<body>
    <form runat="server">
    <p>
        Date:
        <input type="text" id="datepicker" /></p>
    <input type='button' id='t' value='Show Calendar' onclick='$( "#t" ).datepicker( "show");' />
    </form>
</body>
</html>
0
 
Roman GhermanCommented:
I'm glad it has helped you.

By the way you can download a theme from jQuery UI, you can even customize one by yourself there.

------------------------
You can find me on: www.extremedev.blogspot.com
0
 
goodkAuthor Commented:
thanks
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now