In my code, $("#date")
is a textfield with jquery datepicker attached. In the code below, when I select a date, firebug shows this error this.val is not a function
$("#date").change(function(){
var mydate = this.val();
alert(mydate);
});
But when I change this.val()
with $("#date").val()
, it works perfectly and alerts the selected date. Can anyone point out why this.val()
is not working?
EDIT
Sorry, $this was a typo. I actually used this.val(), not $this.val()
this
in your event function isn't a jquery object, it's a dom object. Address it as $(this)
and it should work for you.
$("#date").change(function(){
var mydate = $(this).val();
alert(mydate);
});
You should write
$(this).val();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With