[英]How to fetch row values from mysql database and fill into text boxes by clicking radio button without refreshing page in php?
I want to fetch database values and fill into html text boxes by clicking radio button without refreshing page in php. 我想通过单击单选按钮来获取数据库值并填充到html文本框中,而无需刷新php中的页面。 How can I do this.
我怎样才能做到这一点。
Example- 例-
database values- 数据库值
Emp_Id - 1 Emp_Id-1
Name - Mike 名字-迈克
Industry - IT 行业-IT
Country - UK 国家-英国
HTML display is like this- HTML显示是这样的-
<input type='radio'> | 1 | Mike | IT | UK |
Now if I click radio button then it must fill all text boxes in my html page HTML Text boxes- 现在,如果我单击单选按钮,则它必须填充我的html页面HTML文本框中的所有文本框-
Employee ID : <input type='text' value='1'> <br> <br> Name : <input type='text' value='Mike'> <br> <br> Working Industry : <input type='text' value='IT'> <br> <br> Country : <input type='text' value='UK'>
Hope you understand my requirements and help me at the earliest. 希望您能理解我的要求并尽早为我提供帮助。
You can send an AJAX request to the php script and make it either give back a json string containing the data that you then parse in JavaScript or just return the html structure you want to display. 您可以将AJAX请求发送到php脚本,并使其返回包含要在JavaScript中解析的数据的json字符串,或者仅返回要显示的html结构。
jQuery has a very easy to use AJAX function. jQuery具有非常易于使用的AJAX函数。
You can do this with help of "parseJSON" method of jQuery. 您可以借助jQuery的“ parseJSON”方法来完成此操作。 all you need to do is create a Json string and keep it as radio buttons value.
您需要做的就是创建一个Json字符串并将其保留为单选按钮值。
$json = json_encode(array("id" => "1", "name" => "Mike", "dept" => "IT",
"country" => "UK"));
echo '<input type="radio" name="employee" value="' . $json . '">";
And then you can get this value in jQuery. 然后您可以在jQuery中获得此值。 Like this:
像这样:
var radioValue = $("input[name='employee']:checked").val();
And then parse the json data, like this: 然后解析json数据,如下所示:
var obj = jQuery.parseJSON( radioValue );
And assign the values to the text boxes like: 并将值分配给文本框,例如:
//HTML
Employee ID : <input type='text' id='id' value=''>
Name : <input type='text' id='name' value=''>
// jQuery
$('#id').val(obj.id);
$('#name').val(obj.name);
This way you can get your desired result. 这样,您可以获得所需的结果。 Hope this helps.
希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.