var districtField = document.getElementById("ptdistrict"); districtField.value = data.name;
var districtField = document.querySelector("#ptdistrict"); districtField.value = data.name;
So basically the first line gets the element we want to change and the second line simply assigns the ‘Name’ of the clicked region as the value of the input field. Read more about custom actions.
Preparing your fields
In this example I used Contact Form 7. In order to make it work, I had to include autocomplete:off in the field tag. For other forms the same will probably be needed. Make sure the input you want to target has the autocomplete parameter disabled.