Click here to Skip to main content
15,885,780 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
HTML
<html>
<head>
<title>
Daily Trip Logsheet
</title>
</head>

<body>

<p> Please Put Details </p>

Dry Run: <input id="DryRun" type="text" placeholder="in Km">
<button id="ButtonSubmit" onclick="postContactToGoogle()" type="button">Post</button>

<script>
	function postContactToGoogle(){
		var dryrun = $('#DryRun').val();
		
			$.ajax({
			url: "https://docs.google.com/forms/d/1iHuOmQx0hXKH6DGb2GNUc-yu-0Iiv9PDkKPgAXX3Ldc/formResponse",
			data:{
			"entry_1438934548"
			}
			type: "POST",
			dataType: "xml",
			statusCode: {
			0:function () {window.location.replace("ThankYou.html");},
            200: function () {window.location.replace("ThankYou.html");}
			}
			});
		}
</script>

<script src="http://code.jquery.com/jquery-1.11.0.js"></script>
<script type="text/javascript"></script>


</body>
</html>



[edit]SHOUTING removed - OriginalGriff[/edit]
Posted
Updated 28-Feb-15 0:39am
v3
Comments
OriginalGriff 28-Feb-15 6:39am    
DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalization if you want to be taken seriously.
Afzaal Ahmad Zeeshan 28-Feb-15 6:50am    
Maybe there was a lot of pain in his head, that caused him to shout ;)

Also, you did leave him shouting in the title. :D
OriginalGriff 28-Feb-15 6:59am    
No, I removed the shouting from the title - it just remains as the URL.
Afzaal Ahmad Zeeshan 28-Feb-15 7:00am    
Yes, I did see that one too. :) Notived it later.
Afzaal Ahmad Zeeshan 28-Feb-15 6:50am    
Please see my solution; the actual problem was the jQuery itself. You had included the jQuery package, but had not yet made the jQuery handle the events.

1 solution

Isn't that pretty much simple in your code? jQuery is a library over JavaScript, not a built-in function. You need to first make sure that now jQuery is going to run, you need to handle the document.ready function and then trigger the jQuery code there. You've efficiently written the code to include the library, but not run the library. Edit your code, and write it this way,

JavaScript
function postContactToGoogle(){
     // jQuery runs under this event
     $(document).ready(function() {
		var dryrun = $('#DryRun').val();
		
			$.ajax({
			url: "https://docs.google.com/forms/d/1iHuOmQx0hXKH6DGb2GNUc-yu-0Iiv9PDkKPgAXX3Ldc/formResponse",
			data:{
			"entry_1438934548"
			}
			type: "POST",
			dataType: "xml",
			statusCode: {
			0:function () {window.location.replace("ThankYou.html");},
            200: function () {window.location.replace("ThankYou.html");}
			}
			});
		}
    });


Now once you would execute it, the code would run. Until now, the console would have shown "$ is not defined". Anyways, a good approach to using jQuery is, to write all of your code inside a document.ready handler.

JavaScript
$(document).ready(function () {
   // your code here..
});


Then all of your code would be managed the jQuery way. $ is defined in the jQuery.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900