Set connected field to a value Javascript

Can set an input field to a value at run time but not a connection field even using the field name from a web inspector:


$(document).on('knack-view-render.view_108', function (event, view, data) {
  $('input#field_15').attr('value', 'New Task');  // this works
  $('#view_108_field_38_chzn').attr('value', Knack.getUserAttributes().id); // this doesn't

 Any ideas?

This is absolutely perfect!! Thank you so much, you've helped out massively! I was dubious at first, as seemed like an awful lot of code to update a field, but has so many different uses it's brilliant! Thanks again, Richard (have also updated my name from ananymous....)