DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

View Poll Results: Is This The Best Way To Update A Large Form?

1. You may not vote on this poll
  • Yes

    1 100.00%
  • No

    0 0%
Results 1 to 2 of 2

Thread: Ajax + Php + Update Field

  1. #1
    Join Date
    Apr 2007

    Unhappy Ajax + Php + Update Field

    Hey everyone,

    I'm of coruse a n00b when it comes to ajax and I have a question about updating a record when focus is lost on a form field. Everything is written in php and mysql. I have a form with 100 fields and there is no way to shorten it. I'd like the field to "auto update" after the user has moved away from the field without having to reload the whole form.

    I know the basics of writing a function in java scripting but I'm not quite sure how to actually run a php script inside of javascript. I can pass the values to java script I just need to know what to do next. I have yet to find a clear answer. Can anyone help?? Thnx!!

  2. #2
    Join Date
    Apr 2007
    Hi tommyready, first, you can't run a php code inside a javascript code because PHP is a server side script, and javascript is a client side script, that's means PHP runs on the server, and javascript runs on the browser.
    So, you need away to exchange data between PHP and javascript, here AJAX can help
    try this code:

    function updateField(nameValue){
    var xmlHttp=null;
    xmlHttp=new XMLHttpRequest();
    catch (e){
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    catch (e){
    alert("No AJAX!");
    return false;
    if (xmlHttp.status==200){
    //this will be called after update
    //this will send the data to server to be updated"GET", 'yourupdatepage.php?'+ nameValue, true);

    function doSomethingAfterUpdate(retValFromPHP){
    //retValFromPHP can be any thing you want!

    <form method="post" ...>
    <input type="text" name="text1" onchange="updateField( + '=' + this.value);">
    Last edited by mouaffak; 04-20-2007 at 09:03 PM.

Similar Threads

  1. AJAX for update of list of items
    By NewToAjax in forum AJAX
    Replies: 0
    Last Post: 03-29-2007, 05:37 PM
  2. AJAX, cURL, and PHP
    By chivkea in forum AJAX
    Replies: 0
    Last Post: 03-22-2007, 09:15 PM
  3. Ted, you're a prince!
    By Georgiana Trigg in forum VB Classic
    Replies: 0
    Last Post: 10-29-2000, 12:21 PM
  4. Update Problem in long text field.
    By Vincent in forum Database
    Replies: 0
    Last Post: 10-05-2000, 05:35 AM
  5. Replies: 2
    Last Post: 09-14-2000, 04:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center