Solved

jquery data picker

Posted on 2011-03-13
9
422 Views
Last Modified: 2012-06-21
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
Comment
Question by:goodk
9 Comments
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 35122819
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
 

Author Comment

by:goodk
ID: 35122857
can you show in javascript html, how would you code it? I can follow. thanks
0
 
LVL 9

Expert Comment

by:Roman Gherman
ID: 35123165
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
 

Author Comment

by:goodk
ID: 35125282
thanks, but I really do not want the date to be editable - only should be able to pick from the calendar. thanks
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 11

Expert Comment

by:SAMIR BHOGAYTA
ID: 35125488
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
 
LVL 9

Accepted Solution

by:
Roman Gherman earned 500 total points
ID: 35125771
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
 

Author Comment

by:goodk
ID: 35130374
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
 
LVL 9

Assisted Solution

by:Roman Gherman
Roman Gherman earned 500 total points
ID: 35131639
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
 

Author Closing Comment

by:goodk
ID: 35132780
thanks
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now