Solved

jquery data picker

Posted on 2011-03-13
9
448 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
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 

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
 
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 Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Button function on table is in trouble 3 22
html border input line 7 14
Where does legacy ASP.NET initialize language? 2 25
Possible propagation problem 1 25
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

829 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