Solved

jquery data picker

Posted on 2011-03-13
9
440 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

803 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