When we're querying a database, we will usually need to press a submit button on a form to pass data to another ASP page, which would generate the query, and return the results. In some situations, this page refresh is just plain annoying and takes too long to complete. In this article, Phanix will describe another way to query a database using a combination of web technologies.
Grabbing Data On The Fly - Query and return (Page 4 of 6 )
Firstly, we will want to submit the query keyword in our “MainFrame” frame to the “ProcessFrame’” frame. Create a new page named addbook.asp. Enter the following code into addbook.html:
We have created a new page that contains a frameset. Inside of the frameset, we have two frames: Our main frame, and the frame that will execute an SQL query in the background, “ProcessFrame”.
Create a new file named mainframe.asp, and enter the following code into it:
Our example is fairly simple, and we won’t be concentrating on actually adding the book to the database, rather the code to get a list of authors based on a keyword.
When we click on the “Query” button, the JavaScript SubmitAuthorQuery() function will be called. The SubmitAuthorQuery() function simply changes the URL of the “ProcessFrame” frame to processframe.asp?authorQuery=[query keyword], getting the value of [query keyword] from the “authorQuery” field in form1.
To actually execute the SQL query and return the results to the “MainFrame” frame, we need to create the processframe.asp page, so let’s do that now.