# Programmatically change DatePicker

**URL:** <https://forums.knack.com/t/programmatically-change-datepicker/7211>\
**Category:** Get Answers\
**Created:** [January 6, 2018, 2:52pm UTC](https://forums.knack.com/t/programmatically-change-datepicker/7211 "2018-01-06T14:52:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![IftachOrr37842](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/iftachorr37842/32/216_2.png) [@IftachOrr37842](https://forums.knack.com/u/IftachOrr37842)\
**Post date:** [January 6, 2018, 2:52pm UTC](https://forums.knack.com/t/programmatically-change-datepicker/7211/1 "2018-01-06T14:52:44Z")

</div>

I would like to enrich one of my forms fields automatically.

The server will send the client a date in ISO8601 format, and I would like to populate the DatePicker with that time.

Here is a code snippet.

$(document).on('knack-view-render.view\_18', function(event, scene, records) {  
$("input#field\_20").on("change paste keyup", function() {  
let link = $(this).val();  
   
fetchData(link, function(err, data){  
if(err) {  
console.log(err);  
return;  
}  
// #view\_18-field\_23 is a DatePicker  
**$("#view\_18-field\_23").val(data.iso8601Date);**  
});  
});

function fetchData(someURL, callback) {  
let someAPI = someURL;  
fetch(someAPI, {  
}).then(function(response) {  
var contentType = response.headers.get("content-type");  
if(contentType && contentType.includes("application/json")) {  
return response.json();  
}  
throw new TypeError("Oops, we haven't got a JSON!");  
})  
.then(function(json) {   
console.log(json.data);  
callback(null, json.data);  
})  
.catch(function(error) {   
console.log(error);   
callback(error, null);  
});  
}
