SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: AJAX style form

  1. #1
    SitePoint Addict
    Join Date
    Jun 2005
    Posts
    294
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    AJAX style form

    In my form I have an input box that asks for a name...

    As the user enters the name, I would like the javascript to access the MySQL db and look for names that match this entry. If it matches any of the entries it will display the name with a nice little message next to the input box..."Name Exists"

    How would I go about doing this? Can someone point me to a tutorial or in the right direction?

  2. #2
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,449
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    I moved this to the JavaScript forum as the core work here will be done by Ajax. If you already know how to query a MySQL database with PHP you already know how to do most of the server-side work for Ajax. You just need to know how to spit out the XML properly.

    Like your title said you'll need Ajax to do this. Have you tried to write any code for this? If not, check out some Ajax tutorials to get started and then post whatever code you need help with.

    Ajax sites: http://www.ajaxian.com/, http://www.ajaxmatters.com/r/welcome, http://sourcelabs.com/ajb/archives/2..._mistakes.html

  3. #3
    SitePoint Enthusiast manya's Avatar
    Join Date
    Dec 2005
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mav3n
    In my form I have an input box that asks for a name...

    As the user enters the name, I would like the javascript to access the MySQL db and look for names that match this entry. If it matches any of the entries it will display the name with a nice little message next to the input box..."Name Exists"

    How would I go about doing this? Can someone point me to a tutorial or in the right direction?
    Hi Mav3n!

    For this to work you will first have to know the basic concept of AJAX. After you know this, you can do it very easily.

    Following are few codes that might help you:

    1. You should have a form with input box and put a onSubmit function. The function should look like this:

    2. The function should look some thing like this:

    Code:
    function abc()
    {
    var xhReq;
    xhReq = createXMLHttpRequest();
    xhReq.open('get', 'test_ajax.php?id='+ document.ajax_ex.ajax_select.selectedIndex);
    xhReq.onreadystatechange = onSumResponse;
    xhReq.send(null);
    }
    3. Now this function acts as an AJAX Engine and would communicate with test_ajax.php (in this example code) to process your request (access the MySQL db and look for names that match this entry). Now the file which would actually process your request would be test_ajax.php where you can put codes so that it queries your mysql database and echoes the result.

    <self promotion is not allowed>


    Regards,
    Mani.
    Last edited by stymiee; Feb 9, 2006 at 08:18. Reason: Removed link to website

  4. #4
    SitePoint Addict
    Join Date
    Jun 2005
    Posts
    294
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    test_ajax.php would have a MySQL query in it correct?


    Thank you for the tutorial sites... That's what I was looking for.

  5. #5
    SitePoint Addict
    Join Date
    Jun 2005
    Posts
    294
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would like to thank you guys for your help... I was able to find the tutorial I needed.. Not only was it exactly what I wanted but it also taught me very well... It was a good tutorial... To help other people I will post the tutorial link
    http://ajax.phpmagazine.net/2005/09/..._with_php.html

    Like I said, it was a very informative tutorial and it even taught me how to do it as well. I was able to add onto the .js to make more interesting things.

    cheers

  6. #6
    SitePoint Enthusiast manya's Avatar
    Join Date
    Dec 2005
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by manya

    <self promotion is not allowed>

    Just to let you know that the blog link that I gave was not for self promotion. I have much better way of doing promotion. That was just to help some one in need.

    Regards
    MN


Bookmarks

Posting Permissions

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