Javascript. Show data of a select field, would it have to do it with ajax?

1

What's up? ... I'm a bit new with javascript and wanted to consume something: I have a form that, in addition to several fields, has a select field. This select field when the list is displayed shows the name of records that are in a database.

What I would like to do is, when selecting one, to obtain the other fields that record has, for example: The select field displays a drop-down list of people's names (where name is just a field in the person record that can also have a last name and age). So when selecting an option I want to know how I can do to take the last name and age and then show it on the screen.

This would have to do with AJAX ?, Jquery I think it would not work because I could only get the value of that select truth?

I do not want to pass code because I want to try to see if I can do it on my own, I would like to please if you could guide me more or less how would the steps that I would have to follow .. Thanks from now!

    
asked by Enzzo Perez 27.10.2017 в 04:44
source

1 answer

0

If you can use jQuery, set $.ajax which makes it very easy to make calls with ajax.

The record that is in the database must have a primary key (an id).

When you generate the select , you also generate the option with the names, well in each option include as value the id of the record.

That way you can send that value in ajax to recover the rest of the data in that record.

For the round trip of the data between the browser and the server you can use json.

    
answered by 27.10.2017 в 05:15