Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    May 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    I have posted up my code here:
    http://l2alliance.freehostia.com/random.php

    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.

    WHY IS THIS NOT WORKING??

  • #2
    Regular Coder ralph l mayo's Avatar
    Join Date
    Nov 2005
    Posts
    951
    Thanks
    1
    Thanked 31 Times in 29 Posts
    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)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •