HTML
- Code: Select all
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<title>Main Page</title>
<link rel="stylesheet" type="text/css" href="style/mainstyle.css" />
<script type="text/javascript">
// Record Set Variable
var recSet;
function populateGrape() {
// Grape Select Input element
var glist = document.getElementById("grape");
// Category Select Input element
var clist = document.getElementById("category");
// If Category Selection is valid
if(clist.selectedIndex > 0) {
// Get XMLHttpRequest Object
var ajax = getRequest();
// Prepare GET action to getGrapes.php synchronously
ajax.open("GET", "getGrapes.php?catID="+clist.selectedIndex, false);
// Attach onreadystatechange Event Handler
xmlHttp.onreadystatechange = loadRecordSet;
// Send Request
ajax.send(null);
}
alert(recSet.toString());
// Enable Grape Select Input
glist.removeAttribute("disabled");
}
function populateTable() {
}
function getRequest() {
var req = false;
try{
// most browsers
req = new XMLHttpRequest();
} catch (e){
// IE
try{
req = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
// try an older version
try{
req = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
return false;
}
}
}
return req;
}
loadRecordSet() {
// if completed
if(ajax.readyState == 4) {
// If request successful put response in the Record set variable
if (ajax.status == 200 || ajax.status == 304)
recSet = ajax.response;
alert("got here");
}
}
</script>
</head>
<body>
<hr/>
<h1>Main Menu</h1>
<p>Broad Selection</p>
<div>
<select id='category' onchange="populateGrape()">
<option value="none"></option>
<option value="red">Red Wines</option>
<option value="white">White Wines</option>
</select>
</div>
<p>Grape Selection (you must first select a broad category)</p>
<div>
<select disabled="disabled" id='grape' onchange="populateTable()">
<option value="none">Select Category</option>
</select>
</div>
</body>
</html>
PHP
- Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Cp1252">
<title>Grapes Table Access</title>
</head>
<body onload="getGrapes()">
<?php
function getGrapes() {
//Server Name Variable
$serverName = 'PAUL-PC\SQLEXPRESS';
// Connection Options
$connOptions = array('Database'=>'WineShopDB');
//Connect to DB
$conn = sqlsrv_connect($serverName, $connOptions) or die( print_r( sqlsrv_errors(), true));
//Query String
$sql = "Select GrapeName From WineShopDB.Grapes Where CategoryID =" + $_Get("catID");
// Execute the query (the recordset $rs contains the result)
$params = null;
$rs = sqlsrv_query($conn, $strSQL, $params) or die( print_r( sqlsrv_errors(), true));
//Close the Connection
sqlsrv_close($conn);
//Return Recordset
return $rs;
}
?>
</body>
</html>



