Hey everyone. Got a problem that I really need help solving.

I have a page where a user is able to search a database for certain criteria (species/location/dates etc). What I have so far is when the form is submitted, the values are posted to a PHP script, which performs a MySQL query and then returns the result in json_encode(). What I want to happen is:
- User fills form
- User clicks submit
- Input values held in JavaScript
- JavaScript calls the PHP script that peforms the query and returns result as JSON
- JavaScript gets JSON response, and iterates through placing markers on a Google Map.

Now I have all the key features here, but combining them together is causing me a headache, and I know that AJAX is my solution. Here's my HTML that calls the JS.

<form id="form" name="form" method="post" onclick="getQuery()">

The JS getQuery():

function getQuery(){
    $.ajax({  
        type: "GET", 
        url: 'userquery.php', 
        data: "",  
        complete: function(data){ 
            var test = jQuery.parseJSON(data);
            alert(test.names[0]);
            alert("here");
        }
    },
        "json");
}
getList();

Obviously this needs work in order to produce the results I desire, but at the moment I'm just trying have the response available for handling.

Any help pleeease?

I know there is a post/code snippet about this, but I cannot find it.

Anyway, you need to serialize your form, and pass it as data to your PHP script.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.