<!DOCTYPE html>
<html lang="ru">
<head>
<title>Книги по категориям</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="ru" />
<link rel="stylesheet" type="text/css" href="lab-2-1.css" />
<script type="text/javascript" src="../XmlHttpRequest.js"></script>
<script type="text/javascript">
function fillCategories(){
var req = getXmlHttpRequest();
req.onereadystatechange = function(){
if(req.readyState !=4) return;
var selCategory = document.getElementById("selCategory");
var responseText = new String(req.responseText);
var cats = responseText.split("\n");
for(var i =0; i<cats.length; i++){
if(cats[i] == ' ') continue;
var parts = cats[i].split(":");
var option = document.createElement("option");
option.setAttribute("value", parts[0]);
var optionText = document.createTextNode(parts[1]);
option.appendChild(optionText);
selCategory.appendChild(option);
}
selCategory.size = selCategory.options.length;
};
req.open("GET","getcategories.php",true);
req.send(null);
}
window.onload = function(){
fillCategories();
}
</script>
</head>
<body>
<h1>Книги по категориям</h1>
<form action="#" onsubmit="return false">
<div>
<label for="selCategory">Категория</label>
<select id="selCategory"></select>
<button onclick="alert()">Показать</button>
</div>
</form>
</body>
</html>