Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I have the following script.
<script>
$(function() {
var date = $('#date').datepicker({ dateFormat: 'yy-mm-dd' }).val();
});
</script>
It displays the datepicker when selected the text box. But I want the current date as default in the text box.Help me
Assuming that you are using jQuery UI's datepicker, you can use setDate to set the date.
var date = $('#date').datepicker({
dateFormat: 'yy-mm-dd'
}).datepicker('setDate', new Date()).val();
1)using php you can to it easily as:
<input type="text" id="date" name="date" value="<?php echo date('Y-m-d')?>" />
2)by using datepicker you can do it like below:
var date = $('#date').datepicker({
dateFormat: 'yy-mm-dd'
}).datepicker('setDate', new Date()).val();
Related
Apologies if my title is on the crappy side. I should also start by mentioning that this is an MVC application if that matters.
Here's what I'm trying to do. I want my datepickers to have the following requirements:
The start date must have a range of today - 45 days ago
The end date must not be able to go past today
The end date must come after the start date
Here is what I've tried so far and have gotten the first 2 bullets working:
HTML
<div class="col-md-6 row">
<div class="form-group">
<label for="StartDate">Start Date</label>
<input type="text" id="StartDate" class="form-control" data-provide="datepicker" data-date-start-date="-45d" data-date-end-date="0d">
<label for="EndDate">End Date </label>
<input type="text" id="EndDate" class="form-control" data-provide="datepicker" data-date-start-date="-45d" data-date-end-date="0d">
</div>
</div>
Javascript:
<script type="text/javascript">
$(document).ready(function () {
$("#StartDate").datepicker({
dateFormat: 'mm/dd/yyyy',
onSelect: function (selected) {
$("#EndDate").datepicker("option", "minDate", selected)
}
});
$("#EndDate").datepicker({
dateFormat: 'mm/dd/yyyy',
onSelect: function (selected) {
$("#StartDate").datepicker("option", "maxDate", selected)
}
});
I've tried also removing some of the data attributes in the HTML and instead adding them to the datepicker methods in the javascript to no avail.
I tried using the solutions to these following questions as well to no avail:
how to compare two datepicker date jquery
Twitter Bootstrap datepicker: how to enable only specific daterange
It also appears that most of the examples I've found use JQuery UI 1.9.2. I only use JQuery 1.9.1 and NOT UI. Does that make a difference?
I'm new to javascript and all this other web stuff so I'm sure I'm missing something very simple but any assistance is appreciated.
Well okay it looks like I found my own answer.
Turns out I was using a combination of two different plug-ins.. Oops. So in case anyone else has a problem with validating start date < end date at all times as well as restricting initial start and end dates, here is what I was able to get working.
$("#StartDate").datepicker({
autoclose: true,
}).on('changeDate', function (selected) {
var minDate = new Date(selected.date.valueOf());
$('#EndDate').datepicker('setStartDate', minDate);
});
$("#EndDate").datepicker({
autoclose: true
}).on('changeDate', function (selected) {
var minDate = new Date(selected.date.valueOf());
$('#StartDate').datepicker('setEndDate', minDate);
});
Hi I am using this jquery datepicker. Till now it is fine.
Now my problem is by default a dropdown control is used to select years, months.
I want to change them to Input type number. How to do this?
I tried changing inside the jquery ui code but I am unable to sort it out.
I am attaching sample datepicker fiddle.
Please help me out to find a way to change year and month to number type
Any help would be appreciated.
$("#date").datepicker({
changeYear: true,
changeMonth: true,
dateFormat: "yy-mm-dd",
closeText: "Cancel",
buttonText: "Select date",
currentText: "Today",
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<body>
<input type="text" id="date" style="height:20px;" />
</body>
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am using a date picker from twitter bootstrap and I want to add some validation that your sign up will not suppose to be registered once your date is below 18 years of age, how am I supposed to do that? here is my sample html code for the birthdate:
<label>Date of Birth*</label>
<input type="date" name="birth_date" tabindex="7" style="height: 30px;" required>
If you look down the demo page a bit, you'll see a "Restricting Datepicker" section. Use the dropdown to specify the "Year dropdown shows last 20 years" demo , and hit view source:
$("#restricting").datepicker({
yearRange: "-20:+0", // this is the option you're looking for
showOn: "both",
buttonImage: "templates/images/calendar.gif",
buttonImageOnly: true
});
You'll want to do the same (obviously changing -20 to -100 or something).
Or you can use
$('#dp1').datepicker({
format: 'mm-dd-yyyy',
startDate: '-15d',
endDate: '+0d' // there's no convenient "right now" notation yet
});
You need to validate the user input either using javascript or the scripting language you're going to use.
An example in PHP would be:
<?php
if(isset($_POST['birth_date']))
{
if($_POST['birth_date'] < 1996)
{
echo 'You can not register';
}
}
This question already has answers here:
jQuery UI DatePicker - Change Date Format
(29 answers)
Closed 8 years ago.
I have a simple html form that asks for two dates to select, and on the next page they are used in a MySQL query. Problem is, datepicker uses mm/dd/yyyy as the format, and I need yyyy-mm-dd for MySQL.
Is there a simple way to do this? I don't care if the datepicker's format is changed, or if I have to add a middle step to convert it, but whenever I search for examples they all look way overly complicated and include stuff I'm not even using.
I don't think the code is really important since it's so simple, but here's what I have in the header;
<script>
$(function() {
$( "#datepicker" ).datepicker();
$( "#datepicker2" ).datepicker();
});
</script>
And here's what's in the body;
<form method="post" action="stat_report.php">
<h1>Report Summary</h1>
Format: YYYY-MM-DD<br>
Start Date: <input type="text" name="startDate" id = "datepicker"><br>
End Date: <input type="text" name="endDate" id = "datepicker2"><br>
<input type="submit" value="Submit">
</form>
Like so: $('#someId').datepicker({ dateFormat: 'yy-mm-dd' });
This could solve your Problem: http://api.jqueryui.com/datepicker/#option-dateFormat
this is my problem i've this :
<script>$(function() {$( "#dataInizioBook" ).datepicker();});</script>
<input type="text" id="dataInizioBook" value="01/01/2013"/>
The datepicker will show another date selected when i click the input text.
Thank's for the help.
Try this in case your browser is configured to use different culture:
$(function() {$( "#dataInizioBook" ).datepicker({ dateFormat: 'dd/mm/yy' });});