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:
<html>
<head>
<title> Add Book </title>
</head>
<frameset cols="100%, 0%" frameborder="no">
<frame name="MainFrame" src="mainframe.asp" border="0" noresize>
<frame name="ProcessFrame" src="processframe.asp" border="0">
</frameset>
</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:
<html>
<head>
<title> Add Author</title>
<script language="JavaScript">
function SubmitAuthorQuery()
{
top.ProcessFrame.location.href = 'processframe.asp?authorQuery='+document.form1.authorQuery.value;
alert(top.ProcessFrame.location.href);
}
</script>
</head>
<body leftmargin="20" topmargin="20" marginwidth="20" marginheight="20">
<h1>Add Book</h1>
<form name="form1" action="mainframe.asp" method="post">
Book Title: <input type="text" name="bookTitle"><br>
ISBN: <input type="text" name="bookISBN"><br>
Author: <select name="bookAuthor"></select>
[ Query: <input type="text" name="authorQuery">
<input type="button" value="Query" onClick="SubmitAuthorQuery()"> ]<br><br>
<input type="submit" value="Add Book">
</form>
</body>
</html>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.
Next: The processframe.asp page >>
More ASP Articles
More By Phanix Chen