Jump to content

Need help with multiple $_GET Values


n33dl3

Recommended Posts

Hi there

What is the right way to handle more then one $_GET Value?

--

// Function handles the response from the PHP script.

function handleResponse() {

// If everything's okay:

    if(http.readyState == 4){

    // Assign the returned value to the document object.

        document.getElementById('outcome').value = http.responseText;

       

--

Now let's say I have two ID elements and the response text has two values, how can I send the first value to the first element id and the second to the second element id?

Do I need to add something like"document.getElementById('aer_version').value = http.responseText;" I need to split somehow the response text

Thanks a lot

Regards

RobH

 

Link to comment
https://forums.phpfreaks.com/topic/46109-need-help-with-multiple-_get-values/
Share on other sites

You could use xml or json and that would be much easier. However, you could simply use something to split the response, like a comma or whatever. Then you could split by the divider. I will give you an example.

 

In this example I am going to assume that you are using a | to divide the responses. So lets say the response from your php file is.

Joe Smith | Something about Joe Smith

 

and here is how you could split the response with js.

 

function handleResponse() {
    if (http.readyState == 4) {
        var response = http.responseText;
        //split the response by our separator
         var parts  = response.split("|");
        //write the first part of the split to your first div
        document.getElementById('div1').innerHTML = parts[0];
        //write the second part of the split to your second div
        document.getElementById('div2').innerHTML = parts[1]; 
    }
}

 

Now normally I would say to use xml or json but since you only have two responses coming back i would just do it that way.

 

Hope that helps,

Tom

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.