Skip to content
Advertisement

How to display data in textbox from database MySQL based on selected option?

I have a table “tb_seri” in MySQL, with columns “id_seri”, “nm_seri” and “value_seri”

So, I want to select “nm_seri” in the select option, and then “value_seri” will appear in the textbox afterwards based on “nm_seri” selected

Here is the code to select “nm_seri” from the database

JavaScript

And I’ve tried various codes from here, but I’m still confused.

And this textbox code to display “value_seri”

JavaScript

Advertisement

Answer

In your current js code there is no value it should be nm_seri .Then , you are getting data attribute using data('nm_seri') it should be data('value') and show this value inside input box using $('#value_seri').val(value_seri); .Also ,your function name should match with onchange="myfunction()" so change that as well.

Demo Code :

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement