Reputation: 109
Since Instamapper is closing down and I am doing this project where I am trying to get to the Moon counting how much km I have walked I tried to make my web app, which I could use instead. I got everything working except I wanted to automatically submit my form with data every 5 sec. I tried to use .submit() but it isn't working.
EDIT: The submit() function is not working, here is the error from the console:
Uncaught TypeError: Property 'submit' of object # is not a function
Here is the code:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
setTimeout(function(){
$('form#target').submit();
}, 5000);
});
</script>
<?php
if(isset($_POST['submit'])) {
echo 'works';
}
$device = 'vPhone';
$date = new DateTime();
$timest = $date->getTimestamp();
?>
</head>
<body>
<form action="" method="post" id="target">
<input type="text" value="<?=$timest?>" name="timestamp" />
<input type="text" value="<?=$device?>" name="device" />
<input type="submit" name="submit" id="submit" />
</form>
<script>
var x=document.getElementById("target");
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(showPosition);
} else {x.innerHTML="Geolocation is not supported by this browser.";}
function showPosition(position)
{
x.innerHTML += "<input type='text' name='lat' value='" + position.coords.latitude +
"' disable><br> <input type='text' name='lat' value='" + position.coords.longitude + "' disable> "; }
</script>
</body>
</html>
Upvotes: 0
Views: 298
Reputation: 3917
It's name="submit" id="submit"
that's causing the problem here. Change that to something else - anything, really, I used name="notsubmit" id="notsubmit"
- and your form gets auto-submitted.
Source: http://api.jquery.com/submit/#comment-106178333
Apparantly these attributes somehow override the jQuery submit function so that it is no longer accessible.
Upvotes: 2