简体   繁体   English

如何通过单击单选按钮从mysql数据库中获取行值并填充文本框,而无需刷新php中的页面?

[英]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.

相关问题 如何在不刷新PHP页面的情况下按按钮获取HTML文本框中的数据库值? - How to fetch database values in html text boxes on button press without refreshing page in php? 如何在不使用 GET 数据中的数据刷新页面而不单击按钮的情况下显示 mysql 数据库 - How to display a mysql database without refreshing the page with data from GET data without clicking button 如何从PHP中的sql server数据库中获取数据而不刷新页面 - how to fetch data from sql server database in php without refreshing the page 如何在不刷新php页面的情况下跟踪mysql数据库中的更改? - How to track to changes in mysql database without refreshing the php page? 如何在另一个 select 框的 onchange 事件中使用数据库中的值填充 select 框,而不刷新页面或提交表单? - How to fill select box with values from database on onchange event of another select box and without refreshing the page or submitting the form? 如何在不刷新页面的情况下获取? - How to fetch without refreshing the page? 在没有PHP的HTML页面上显示MySQL数据库中的值 - Show values from MySQL Database on HTML page without PHP 如何通过单击表格行来检查单选按钮? - how to check a radio button by clicking on a table row? 如何在提交按钮上运行php代码而不刷新/重新加载页面 - how to run php code on submit button without refreshing/ reloading the page 如何在不刷新页面的情况下将值从jsp页面发送到数据库 - How to send value from jsp page to database without refreshing the page
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM