Skip to content
Advertisement

Perform special functions with drop-down menu

I’ve been sitting on a certain function for quite some time now. After a lot of research and testing, I have not come up with a final solution. solution. The user should be able to select which table row he wants to edit with the help of a dropdown menu. Based on the dropdown selection after confirming a button, input fields should appear in the corresponding row, so that the user can correct erroneous data manually. manually in case of erroneous data. However, the input should only overwrite the respective cell if something has been typed there (input field). My table always consists of 10 rows, thus 10 dropdown selection options.

How the buttons work:

edit = make the fields appear after dropdown selection

confirm = make fields disappear again and overwrite what has been written in the fields in the respective cells but only if something has been typed there

How I manually insert input fields in the respective table cells I already know and have implemented in this way:

JavaScript

My table (embellished with bootstrap) and dropdown selection looks like this.

Table:

JavaScript

Dropdown:

JavaScript

I know that one implements this with the if/else query, only I don’t know exactly how to combine the selection from the dropdown with the confirmation button and the if else query. Surely one connects the if/else query with the ID’s of the respective options of the dropdowns.

Some screenshots (visualizations) of how this should look like.

before the selection: 1

after the selection: 2

Unfortunately I am still a beginner in Javascript and HTML and hope that you can help me. I hope that I have described and shown everything well and I apologize in advance for my not so clean English. Thank you!

Advertisement

Answer

Dropdown and button

JavaScript
JavaScript

I’ve added a codepen here. Hope you can use this as an example and go forward from here.

Advertisement