/    Sign up×
Community /Pin to ProfileBookmark

New To Ajax; Auto Submit Form

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>[/CODE]

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @robindean spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.10,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...