Question

I've got a question, got couple of input datepickers like

<input name="datepicker_one" class="datepicker" readonly type="text" value="12-12-2013" />
<input name="datepicker_two" class="datepicker" readonly type="text" value="13-12-2013" />
<input name="datepicker_three" class="datepicker" readonly type="text" value="14-12-2013" />

and I'm trying to get values of clicked datepicker, while trying to avoid writing different methods for each of those inputs, so I wonder if there is a way to get datepicker value just by clicking on input with class .datepicker like:

$(".datepicker").click(function(e){ $(this).val(); });

but this gives me undefined value also:

$(".datepicker").click(function(e){ $(this).datepicker("getDate"); });

Does not seems to work.

Was it helpful?

Solution

You aren't using your value. The statment:

$(this).val();

Is meaningless as it doesn't do anything. You get the value, but didn't use it. If you did

console.log($(this).val());

you would actually see the result.

OTHER TIPS

Try this:

    $(".datepicker").click(function(){
        alert($(this).val());
        return false;
    });
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top