Grow your CSS skills. Land your dream job.

AJAX form not working…

  • # June 17, 2010 at 8:14 am

    Hi,

    I’m trying to make an AJAX contact form for my first time, and right now – it’s very simple. I don’t have it doing anything right now, except for when someone submits something – it checks to see if they entered a name, and if they didn’t, it tells them to – that’s it.

    Anyway, for some reason, it’s not updating the page when I press the button after entering information into the form. If anybody could help me figure out what I’m doing wrong, I would really appreciate it. This is some of my first experience with AJAX/Javascript, so please, don’t hold back ;)

    Here’s the code for the form:

    Code:


    Name:
    Email:
    Comments:

    Your result will display here.


    And here’s the code for the PHP file, called send-form.php:

    Code:
    < ?php
    $name = $_GET['name'];

    echo 'Name is: ' . $name . '
    ‘;
    ?>

    Thank you in advance for your help!

    # June 17, 2010 at 4:06 pm

    Might I suggest JQuery? It is a javascript library that can make life easier, especially when it comes to simple ajax. It’s how I learned, and works in just about every browser you can think of.

    http://docs.jquery.com/Main_Page

    Ajax is on the left hand side on the menu for tutorials.

    I did what you want in only a minute with jquery, and notice how much shorter and forward it is. Easier to learn if you ask me.

    Code:


    Name:
    Email:
    Comments:

    Your result will display here.


    I know this isn’t exactly what you asked for, and if you want I will take a look at what you had and see if I can find your problem. Just note that if you use my example, you will need to have the jquery library and change the src to where it is on your server and also change the send form to receive a post instead of a get.

    Best of luck,
    -T

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".