开发者

filling the text area using PHP

I have a PHP Script which has several text areas. What I would like to do is enter id in one text box and based on the id entered i need to get some data from MySQL database and put it the textarea inputs.

There will be one text area with get button where we will enter id and the remaining text areas are title,name etc.,all of these are in mysql DB.By entering 'id' in 'id' text area the information of the other fields(title,name etc) need to be fetched and entered into the text areas.

I was told that using Jquery is much better for this, but am having a very hard time finding documentation that would show me how to do.I do not know Javascript, but could definitely follow instructions if a good tutorial was provided. Does anyone have any references or links?

Thanks for y开发者_如何学JAVAour time.


jquery .get() could be helpful http://api.jquery.com/jQuery.get/:

$("#yourButton").click(function(e){
    e.preventDefault();
    var id = $("#idfield").val();

    $.get("test.php", { id: id },
       function(data){
         $("#namefield").val(data.name);
         // rest of your data
     },"json");

});

Use php to return your data as json with the json_encode function http://php.net/manual/en/function.json-encode.php


Take a look at the jQuery ajax function. It can be used to call a php page the returns either the value or some JSON to populate you textarea with.

Here is an example:

http://net.tutsplus.com/tutorials/javascript-ajax/5-ways-to-make-ajax-calls-with-jquery/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜