Dear ajax expert,

http://www.w3schools.com/php/php_ajax_php.asp

Refer to the link, using the sample, I'm able to use php ajax to populate 1 text box which I've already pre-define (not using "echo '<input type='text'..") -- the info came from a table

e.g.

Search: [jo ]

Name: [John doe]

sql
---
select name from customer where name like '%jo%';

Question
========
How do I populating 3 text boxes?

e.g.

Search: [jo ]

Name: [John doe]
Address: [123 city state postcode]
Tel: [012-3456-7890]

sql
---
select name, address, telno from customer where like '%jo%';

I've been googling this solution, but no solution found

Please Help!

Regards

You could pass the text/xml result from the ajax when it is done to a JavaScript, and then use the function to populate your result in your predefined HTML elements?

You could pass the text/xml result from the ajax when it is done to a JavaScript, and then use the function to populate your result in your predefined HTML elements?

Thanks for the reply tywin

It looked like a good solution, but

Can you show me the sample coding?

Sorry if this question sound silly

Obviously I'm new to ajax

OK, using script portion from the link you gave in your first post. You need to craft the response back from ajax as a string with certain delimiter for the response, so you can use it in your ajax response.

The example below expect your ajax to return a string containing data in the format as name_string:::address_string:::phone_string. Then you don't need a function but work it on right inside the ajax part.

// expecting the result string from ajax as
// name_string:::address_string:::phone_string
xmlhttp.onreadystatechange=function() {
  if (xmlhttp.readyState==4 && xmlhttp.status==200) {
    var strArray = xmlhttp.responseText.split(":::");
    document.getElementById("result_name").innerHTML=strArray[0];
    document.getElementById("result_address").innerHTML=strArray[1];
    document.getElementById("result_phone").innerHTML=strArray[2];
  }
}

Remember that you need to return the value from ajax as string and use a delimiter when concatenate your result. That should eliminate your problem.

Excellent!

It works Taywin, you are a star!

I hope this solution crawl by google, and become help to others too

Regards

OK, using script portion from the link you gave in your first post. You need to craft the response back from ajax as a string with certain delimiter for the response, so you can use it in your ajax response.

The example below expect your ajax to return a string containing data in the format as name_string:::address_string:::phone_string. Then you don't need a function but work it on right inside the ajax part.

// expecting the result string from ajax as
// name_string:::address_string:::phone_string
xmlhttp.onreadystatechange=function() {
  if (xmlhttp.readyState==4 && xmlhttp.status==200) {
    var strArray = xmlhttp.responseText.split(":::");
    document.getElementById("result_name").innerHTML=strArray[0];
    document.getElementById("result_address").innerHTML=strArray[1];
    document.getElementById("result_phone").innerHTML=strArray[2];
  }
}

Remember that you need to return the value from ajax as string and use a delimiter when concatenate your result. That should eliminate your problem.