I have a jquery/ajax geolocation script that outputs data such as:
$.ajax({
url: "https://geoip-db.com/jsonp",
jsonpCallback: "callback",
dataType: "jsonp",
success: function( location ) {
$('#country').html(location.country_name);
}
});
I'm trying to get it to include that in a php form in a hidden field when the rest of the form is submitted. But so far I can't seem to get the geolocation script's data to submit with the form.
The important bit from the php form handler would be:
Country: " . $_POST['field_7'] . "
And in the html form I've tried:
<input type="hidden" name="field_7" id="#country" value=''>
And various other things like value="$('#country')" but the geolocation data is not being posted/emailed with the form. How can I get the data the geolocation script captures to post to the hidden input in the form?
#in jquery meansid=, so you don't want the#in your id, change<input type="hidden" name="field_7" id="#country" value=''>to<input type="hidden" name="field_7" id="country" value=''>. And then set with$("#country").val(location.country_name);- edit: as someone answered.$('#\\#country').val(location.country_name);