I have a text field that holds a difference between days. I need to use it calculate something on my page. However, for some reason it is coming back as undefined
when I do a console.log()
. Any ideas?
<script>
$(document).on('change', '#unitselector', function()
{
var unit = $('select option:selected').text();
var rate = $(this).val();
var tax = $('select option:selected').attr('label');
var depart=$('#departdate').val();
var arrival = $('#arrivaldate').val();
var dataString = {unit:unit, depart:depart, arrival:arrival};
console.log(dataString);
//console.log($('.extracharges').serialize());
$.ajax({
type: "POST",
url: "classes/unit_info.php",
data: dataString,
cache: false,
success: function(html)
{
$('.unitinfolist').html(html);
}
});
var days = $('#days').attr('name');
var days2 = $('#days').attr('value');
console.log('days: '+days);
console.log('days: '+ days2 );
$('.rentalcharges').find('#rent').val(rate*days);
});
</script>
and the PHP
$arrive = $_POST['arrival'];
$leave = $_POST['depart'];
$a = date_create($arrive);
$d = date_create($leave);
$diff = date_diff($d,$a);
echo '<input type="text" id="days" value="'.$diff->d.'" name="'.$diff->d.'" />';