0

Hello everyone, I am currently creating a small JS app. that will help me search PostgreSQL and print related data via PHP. I am using jQuery to help me but I have this small problem. I wanted to test if the code worked, by prompting the PHP file to print a random text before moving on to data but I had this error in Firebug -nothing is printed as an output-:

"Element referenced by ID/NAME in the global scope. Use W3C standard document.getElementById() instead.
[Break on this error] $.post('file.php', {name: form.name.value },"

my javascript and php code are below:

JAVASCRIPT

<head>
   <style type="text/css">
   #age{
		display: none;
		line-height: 0px;
		font-size: 20px;
	}
	</style>
   
   
   <script type="text/javascript" src="jquery-1.4.2.js"></script>
   <script type="text/javascript">
   
		function get(){
		
			$.post('file.php', {name: form.name.value },
				function(output) {
				
					$('#date').html(output).show();
				
				});
		}
   
   
   </script>
   
   
   
 </head>
 <body>
 
 <p>
 <form name="form">
 
	<input type="text" name="name"><input type="button" value="Get" onClick="get();">
 </form>
 
 <div id="date"</div>
 </p>
 
 </body>
 </html>

PHP

<?php

echo "a random sentence";

Any ideas about the problem ? Thanks.

?>
2
Contributors
2
Replies
4
Views
6 Years
Discussion Span
Last Post by koveras vehcna
0

In the form : give the inputs an ID

<input type='text' id='someID' value='Get' />
<input type='button' id='someButton' value='Get' />

Change the javascript :

$(function() {
$('#someButton').click(function() {
    var resp = $.ajax({
    type: 'POST',
    url: 'file.php', 
    data : {'name': $('#someID').val()},
    async: false}).responseText;
    $('#date').html(resp);
});
});

Check out the code at http://docs.jquery.com

Edited by soldierflup: n/a

0

In the form : give the inputs an ID

<input type='text' id='someID' value='Get' />
<input type='button' id='someButton' value='Get' />

Change the javascript :

$(function() {
$('#someButton').click(function() {
    var resp = $.ajax({
    type: 'POST',
    url: 'file.php', 
    data : {'name': $('#someID').val()},
    async: false}).responseText;
    $('#date').html(resp);
});
});

Check out the code at http://docs.jquery.com

Thanks a ton.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.