Skip to content
Advertisement

default values in input form Modal

I just created a datatable collecting the values ​​from a wordpress database.- These values ​​must be loaded in a contact form within a modal. I am calling the modal from a button in the last column of each row of the datatable. I must predetermine the values ​​of the form fields with the information corresponding to each row. Example: I click the button in row 3, it should open the modal with the form and the fields already filled in with the information in row 3

The problem I have is that it doesn’t happen that way. If I click the buttons randomly, it loads the modal and the form with the data in the sequence of row1, row2, row3, etc. Example: if I click the button in row 1, it opens the modal with the form and the data in row 1 But if I then click on button 5, it opens the information of row 2 (it should load me the info of row 5) If then I give the button of row 8 (or any other) it loads me the information of row 3 and so on

If someone can tell me where the problem is or give me another solution to load the data of each row within each form

php Code

JavaScript

Modal

JavaScript

Form

JavaScript

Advertisement

Answer

You can use jquery to populate modal form fields when you open up modal. Give your modal form elements unique ID like this.

JavaScript

Then you can use the following jquery function to populate modal form values when Enquire Now button is clicked.

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