check the value of startDate before setting it in date field by using alert(startDate) or consol.log(startDate). From your code it seems that you are passing an array to the val() method and not a single value
DanyalHaider
var startDate = data[0]['get_start_date'].split(" ");
In the above code data[0]['get_start_date'].split(" ") actually returns an array you have to specify the correct index for this array to use that value with val() . Check the code below
var startDate = data[0]['get_start_date'].split(" "); // this returns an array named startDate
// e.g if data[0]['get_start_date'] = "11/24/2016 12:00:00 AM" then
// startDate[0] = "11/24/2016" and startDate[1] = "12:00:00 AM"
//I assume you will be using only the date part then you can use the first index like below
$("#clndr_UPdateStartDate").val(startDate[0]);
Also please post the structure of "data" that you are receiving in your ajax success callback if this doesn't work.
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
21 Points
137 Posts
set date in html textbox from ajax
Nov 24, 2016 04:57 PM|DanyalHaider|LINK
I am trying to set value in html input having type Date. But don't know it's not working here is my code :
$.ajax(
success: function (data)
{
var startDate = data[0]['get_start_date'].split(" ");
$("#clndr_UPdateStartDate").val(startDate);
});
Waiting for the positive reply
Member
370 Points
137 Posts
Re: set date in html textbox from ajax
Nov 24, 2016 06:33 PM|Nilishere|LINK
check the value of startDate before setting it in date field by using alert(startDate) or consol.log(startDate). From your code it seems that you are passing an array to the val() method and not a single value
In the above code data[0]['get_start_date'].split(" ") actually returns an array you have to specify the correct index for this array to use that value with val() . Check the code below
Also please post the structure of "data" that you are receiving in your ajax success callback if this doesn't work.
Member
160 Points
54 Posts
Re: set date in html textbox from ajax
Nov 24, 2016 11:06 PM|Sangit|LINK
Hi ,
Your id is not matching, make sure your id is $("#clndr_UPdateStartDate")
check the below link to set date value.
http://stackoverflow.com/questions/12346381/set-date-in-input-type-date
Star
8670 Points
2882 Posts
Re: set date in html textbox from ajax
Nov 25, 2016 08:49 AM|Cathy Zou|LINK
Hi DanyalHaider,
As far as I know, Two problems in this:
1.Date control in HTML 5 accepts in the format of Year - month - day as we use in SQL
2.If the month is 9, it needs to be set as 09 not 9 simply. So it applies for day field also.
Following is an working example, you could refer to it:
CodeBehind:
Output screenshot as below:
Best regards
Cathy
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.