how can AJAX write to a "pre-existing" table cell by using its name.

I am a newbie to AJAX. Here is my problem, I have a table already built in HTML as follows on page -1.
My table is fixed length so I do not have to worry about building dynamically it using echos in page-2.

Page-1 calls Page-2 with a xmlhttprequest; which works fine.

Page-1

row 1, cell 1 row 1, cell 2
row 2, cell 1 row 2, cell 2
............. ............. Notice that all my cells have names! ....................................Now that my cells are named I hope to write to them in my php page as follows: page-2


MySql gets used here, which works fine.


echo… print or write or whatever $my_mysql_ whatever_variable to cell12 ( or any cell), etc,etc,etc…<<<<<<<<<<<…this the line I really need help with.

Notice that cell12 and the other 3 cells already exist and just need to be populated.
Thanks

There’s lots of examples on the internet just Google “Populate Form Elements with Ajax” or “populate input fields with ajax”

[php] $.ajax({
url: “yoururl.php”,
success: function(data){
//set the value of your input field with the data received
$(’#cell11’).val(data);
}
}
);[/php]

Here is my really simple page-2 which is just php. Nothing happens and Dreamweaver does not like the $.ajax…

<?php echo "php beginning"; $num = 45; $.ajax({ url: "ajax-c.php", success: function($num){ set the value here $('#cell11').val($num); } } ); ?>

Does #id also match elements to the name attribute? Sounds strange. Wouldn’t he have to do this:
[php]$(“td[name=‘cell11’]”).val(data);[/php]

Thanks to everyone for the samples above. I am trying to use the following sample given to me from above:
$.ajax({
url: “yoururl.php”,
success: function(data){
//set the value of your input field with the data received
$(’#cell11’).val(data);
}
}
);

When I place this in my php page ( where I do need it), Dreamweaver flags most of the lines as invalid syntax.
But when I place it in my HTML page, Dreamweaver likes all of it. But that is NOT where I need it.

What am I missing here?
Thanks

Where does JavaScript normally go?

Ok, I guess what I want is not possible.
So the only two ways that I can see to write from my page-2(which is all php) back to page-1(which is all html), is to:

  1. use many echos to build a table and populate it, I find this really ugly.
  2. bundle the entire result set into the responseText and send it back and then parse it in page-1 into my table.

Is there a better, more elegant way ?

Thanks

Sponsor our Newsletter | Privacy Policy | Terms of Service