View Full Version : Please read my small php / javascript code! WHY DOESN'T IT WORK??

05-28-2007, 11:35 PM
I have posted up my code here:

Here is what it is supposed to do (but does not):
1. The user inputs a message in the "text" input
2. The user can submit the message in two ways: one is by pressing enter (HTML character 13), or by clicking on the "enter" button.
3. If the user presses the enter key (HTML character 13), function entered(event) calls function submitmessage().
4. If the user clicks on the "enter" button, function submitmessage() is called directly
5. function submitmessage() gets the value of whatever is written in the textbox, and outputs the following: "<?php chatsave(THE_MESSAGE); ?>". This is written in the <div id="coding"></div> section.
6. Basically, this should call the php function chatsave with sending it THE_MESSAGE that the user has written.
7. The chatsave php function simply saves the message and other info in the database.


ralph l mayo
05-29-2007, 01:01 AM
PHP is executed on the server, not in the browser. Adding PHP blocks to the document with JavaScript is not going to work. You need to make another connection back to the server to deliver the data needed to run the server-side script, either by simply posting the form or by using the XmlHttpRequest object (cf: google for AJAX, SPA)