Page 1 of 1

HOW TO GET A DATE AS STRING FROM DATEPICKER

Posted: Tue Aug 13, 2013 5:48 pm
by Pasteur Miranda

Hi,

Code: Select all

I have a datepicker named dpini placed inside a page named HistoricoPage. I placed the following code inside PageShow event of HistoricoPage: 

var dataini = $('#dpini').datepicker({ dateFormat: 'dd-mm-yy' }).val();
alert (dataini);

I want that, entering the page, to show the selected date in the alert. The problem is: the alert shows the message "undefined". Is there anything wrong with the code above? How can I get the date returned by datepicker as string?

Thank you


HOW TO GET A DATE AS STRING FROM DATEPICKER

Posted: Tue Aug 13, 2013 6:23 pm
by Kateryna Grynko

Hi,

Try this code:
codevar dataini = $('#dpini').datepicker("formatDate", 'dd-mm-yy');
alert (dataini);/code
Read more here: http://api.jqueryui.com/datepicker/


HOW TO GET A DATE AS STRING FROM DATEPICKER

Posted: Tue Aug 13, 2013 8:37 pm
by Pasteur Miranda

Hi Katya,

Code: Select all

I tried this code and the alert shows the message [object Object] . Is there any way of getting this object as string? 

Thank you.


HOW TO GET A DATE AS STRING FROM DATEPICKER

Posted: Tue Aug 13, 2013 9:04 pm
by Kateryna Grynko

Are you sure code$('#dpini')/code returns date input field?

You should probably use codeAppery( "mobiledatapicker_name")/code to access it.


HOW TO GET A DATE AS STRING FROM DATEPICKER

Posted: Tue Aug 13, 2013 9:22 pm
by Pasteur Miranda

Hi Katya,

Code: Select all

I changed the name from "mobiledatepicker_name" to dpini.  I call the alert inside the pageshow method. 

Thank you


HOW TO GET A DATE AS STRING FROM DATEPICKER

Posted: Wed Aug 14, 2013 1:48 am
by Pasteur Miranda

Hi Katya,

I tried unsuccessfully to get the date as string. Any other suggestion?

Thank you.


HOW TO GET A DATE AS STRING FROM DATEPICKER

Posted: Wed Aug 14, 2013 3:20 am
by Pasteur Miranda

I found the solution:

Rename the datepicker input field (my datapicker is named dpini and the input field is renamed to inputdpini):

$("[name='dpini']").find('input').attr('id','inputdpini');

Get the input field value as string and show it in the alert:

var dataini = $("#inputdpini").val();
alert(dataini);

Thank you all.