Reputation: 185
JAVASCRIPT
I am just trying to returen the value of the date selected but it's coming back undefined.
var getDate = function() {
var bdinput = $('#bd.bdinput').val();
var _this = bdinput;
console.log(_this);
};
$("button.bdsubmit").click(function() {
console.log(getDate());
})
HTML
<form id="bd">
<input name="BirthDate" class="bdinput" type="date" />
<button class="bdsubmit" type="submit">Submit Date</button>
Upvotes: 1
Views: 4096
Reputation: 185
It was a simple mistake.
var bdinput = $('#bd.bdinput').value;
should be:
var bdinput = $('#bd. bdinput').val();
Upvotes: 0
Reputation: 57095
You need .val()
to get value of input not .value
var bdinput = $('#bd .bdinput').val();
// ^ also need space here
$('#bd .bdinput')
will select element with class bdinput
inside element with id bd
.
$('#bd.bdinput')
will select a element with id 'bd' and class bdinput
(both id and class in one element)
.value
var bdinput = $('#bd .bdinput')[0].value;
Or
var bdinput = $('#bd .bdinput').get(0).value;
Upvotes: 3