How to show the selected date in datepicker? - javascript

I'm Working with Asp .net MVC3.i'm having a text box with a datepicker image that textbox having a date filled in it.when i click select the datepicker image the popped up datepicker has to be pointing out the date which is in textbox instead of pointing the current date.Is there any jquery for this?

Use the setDate option :
$('element').datepicker({
defaultDate: '02/02/12'
}).datepicker('setDate', '02/02/12');
FIDDLE

Works just fine by default.
See fiddle: http://jsfiddle.net/ymLe2/1/
$('#dated').datepicker({showOn: "button"});
You need to post your code, so as to be able to identify the cause of your problem.

Related

I don't want datetimepicker setting default value on click

I have a text input to which I have applied a DateTimePicker plugin
But when I click on the input before opening the DateTimePicker, it sets default value as current date, I want the value to stay empty as long as the user selects it from the DateTimePicker.
$('.datepicker').datetimepicker({
format: 'DD/MM/YYYY',
});
The DateTimePicker Library which i am using is:
eonasdan.github.io/bootstrap-datetimepicker
I have mentioned the answer in the comments above but just posting it as an Answer for someone who might face the same issue in the future
Initialize the DateTimePicker with useCurrent as false as shown below:
$('.datepicker').datetimepicker({format: 'DD/MM/YYYY',useCurrent:false});

JS, jQuery, how to dynamically update/refresh datepicker value after changing the input value

I'm trying to dynamically change the date picker value
I'm changing the input value using Jquery but unfortunately, date picker value stays the same.
image of the problem
You can see that the initial value is "19/06/2017" and after changing it shows the new value ("10/10/2017") in the text box but date picker still shows the previous date ("19/06/2017")
I tried using $('.datepicker').datepicker('update', $('#doc_due_date').val()); but still nothing changed
Is there a way update or refresh the date picker after changing the input value?
I read some answers regarding the same issue but seems like nothing worked, date picker still shows the initial value
thanks in advance.
p.s
I'm using bootstrap date picker
use this
$('#datepicker_id').datepicker({
onSelect: function () {
$('#data').text(this.value);
}
});

how to add field in form in yii1 with ajax?

I am using date picker widget in my YII1 form. I also have a button to add more dates. When the page is first time loaded the date picker widget works. When I click on add more button, I added the new filed to the from but at that time date picker does not work.
How can I add datepicker widget fields on ajax to a form?
or there is any other way doing?
In Ajax Success re-initialize datepicker
$( "#datepicker" ).datepicker();
your problem will solve.better if you post your code here
I think your issue is because of 'Id'
You just change the datepicker displaying attribute from 'Id' to 'Class',
Ie,the newely added fields id and already added fields id,s are same so date picker wont work with multiple with same id,so you should change the datepicker displaying attribute from 'ID' to 'Class'
then, it will work fine

Enter text in Datepicker textfield

I'm using jQueryUI to add a datepicker to a textfield. It all works fine, but because of this i'm not able to type any text into the textfield. I can only add a date through the datepicker.
But i want users to be able to also enter things like NOW in the textfield. But currently entering manual text is blocked as you can see in this example fiddle: http://jsfiddle.net/Kugzd/
Is there anyway to change this behavior?
Just add constrainInput: false to your datepicker option
$(function() {
$('.date').datepicker({
constrainInput: false
});
});
Check the documentation
Demo: http://jsfiddle.net/Kugzd/2/
In addition to using constraintInput option (as noted by another answer), consider combining the datepicker along with Date.js library, which allows you to work with words and expressions such as today, tomorrow, next Tuesday and turn them into dates.

Minimum and maximum dates for datepicker

I am using jQuery for making a datepicker and I am facing the following problem with it:-
I want to show a minimum date of 1970 in the drop down menu of the calender which I am not able to do.
I also want to show a maximum year of (current year - 20) in the same drop down.
How can these things be done?
Also, I want to monitor a text box using jQuery for keystrokes. When the third character is entered in the text box, I want to make an Ajax call to get all the fields from a db which matches those 3 starting characters and show them in a suggestion box.
Can anyone please tell me how these problems can be resolved?
have a look at the jquery ui docs - you'll find "yearRange" under options
http://jqueryui.com/demos/datepicker/
For the second question, also jquery ui:
http://jqueryui.com/demos/autocomplete/
You can use
$(function() {
$( "#datepicker" ).datepicker({ minDate: new Date(1970,1, 1), maxDate: "-20Y" });
});
See
http://jqueryui.com/demos/datepicker/min-max.html

Categories

Resources