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.

?>

Recommended Answers

All 2 Replies

Member Avatar for soldierflup

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.