Skip to content
Advertisement

Pass GET Variable to Modal to use in Query

I am trying to build a budget lookup tool. I have form where someone enters an account#, fund#, and deptID#. When they hit search, it opens a modal and will display a table of the budget balances that match the entered fund, account, and deptID.

I can get the modal to open but, I can’t seem to get the data to pass to the modal and display the data based on the SQL query. Here is my code:

Here is the form:

JavaScript

Here is the script and modal:

JavaScript

Here is the SQL query:

JavaScript

Advertisement

Answer

You have things out of sequence. The select/submit button should trigger a back-end operation to retrieve the data from the database (through an ajax request), which would then return the data to your page as JSON which you could parse in javascript into HTML- OR – instead of returning JSON data, you could return the HTML for your modal. Maybe something like this

JavaScript

Your MOdal HTML could become:

JavaScript

and your PHP script, something like:

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