Hi all.
I’m trying to auto submit a form using Ajax. My current code is as follows. Everything is working. I’d simply like to know what’s missing that would send the form automatically.
Note: I’m using the WordPress noConflict method, hence the $j variable.
[CODE]<div id=”moto_weather_div”>
<form id=”moto_weather” name=”location” action=”##########” method=”post”>
<input id=”coords” type=”hidden” name=”coords”>
<input type=”text” name=”location_search” value=”Enter Zip Code (Or Leave Blank)” onfocus=”if (this.value == this.defaultValue) this.value = ”” onblur=”if(!this.value) this.value = this.defaultValue”>
<br />
<input type=”submit” value=”Update” style=”margin-top:16px;width:100%”>
</form>
<script>
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var lat = position.coords.latitude;
var lon = position.coords.longitude;
document.getElementById(“coords”).value = lat + “,” + lon;
});
};
var $j = jQuery.noConflict();
$j(“#moto_weather”).submit(function () {
$j.post(“##########”, $j(“#moto_weather”).serialize(), function (data, textStatus) {
$j(“#moto_weather_div”).html(data);
});
return false;
});
</script>
</div>