Pasteur Miranda
Posts: 0
Joined: Thu Aug 01, 2013 2:59 am

HOW TO GET A DATE AS STRING FROM DATEPICKER

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

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

HOW TO GET A DATE AS STRING FROM DATEPICKER

Hi,

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

Pasteur Miranda
Posts: 0
Joined: Thu Aug 01, 2013 2:59 am

HOW TO GET A DATE AS STRING FROM DATEPICKER

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.

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

HOW TO GET A DATE AS STRING FROM DATEPICKER

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

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

Pasteur Miranda
Posts: 0
Joined: Thu Aug 01, 2013 2:59 am

HOW TO GET A DATE AS STRING FROM DATEPICKER

Hi Katya,

Code: Select all

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

Thank you

Pasteur Miranda
Posts: 0
Joined: Thu Aug 01, 2013 2:59 am

HOW TO GET A DATE AS STRING FROM DATEPICKER

Hi Katya,

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

Thank you.

Pasteur Miranda
Posts: 0
Joined: Thu Aug 01, 2013 2:59 am

HOW TO GET A DATE AS STRING FROM DATEPICKER

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.

Return to “Issues”