John Davidson

javascript - Not showing Date value for input field

0 comments
Message:


I have two input date fields. I need a second input date field value based on the first input date field selection.


HTML:-


<label>First input date </label>
<input type="date" name="job_date" id="job_date" style="width:100%;" required>

<label>Second input date </label>
<input type="date" name="due_date" id="due_date" style="width:100%;" required>

Script:-


<script type="text/javascript">

$('#job_date').change(function(){

var pazdate = $('#job_date').val();

$.ajax({
url: 'ajax1.php',
type:'POST',
data: {pazdate: $('#job_date').val()},
success: function(data) {
$('#due_date').val(data);

}

});

});

</script>

PHP Form


<?php
if (isset($_POST['pazdate']))
{
$currentDateTime = $_POST['pazdate'];
$nextdue_date = strtotime("+12hours", strtotime($currentDateTime));
$due_date = date("m/d/Y", $nextdue_date);
echo $due_date;

}

?>

Any help greatly appreciated.



My Answer:
html





Date Input Example













In this code snippet, the second input date field (`end-date`) will automatically update its value to match the value of the first input date field (`start-date`) whenever the user selects a date in the `start-date` field. The `disabled` attribute is added to the `end-date` field to prevent the user from manually entering a date in that field.

Rate this post

4 of 5 based on 3819 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us