Hi,
I was going through this tutorial:
http://www.electrictoolbox.com/json-...ery-php-mysql/
and I changed it round slightly, I would like the first select box to be Search by either Town or County - Having links would easier?!
http://www.mypubspace.com/dashnew/
So, when a user selects Town, the PHP selects the Towns or if the user selects County, then show the Counties list
I am currently getting the following error: $ is not defined
[Break On This Error] $(document).ready(function() {
here is my HTML
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<script language="javascript" type="text/javascript">
function populateFruitVariety() {
$.getJSON('search-by.php', {fruitName:$('#fruitName').val()}, function(data) {
var select = $('#fruitVariety');
var options = select.attr('options');
$('option', select).remove();
$.each(data, function(index, array) {
options[options.length] = new Option(array['variety']);
});
});
}
$(document).ready(function() {
populateFruitVariety();
$('#fruitName').change(function() {
populateFruitVariety();
});
});
</script>
</head>
<body>
<form>
Search by:
<select name="name" id="fruitName">
<option>Please Select</option>
<option id="Town">Town</option>
<option id="County">County</option>
</select>
Variety:
<select name="variety" id="fruitVariety">
</select>
</form>
</body>
</html>
PHP
Code:
<?PHP
$dsn = "mysql:host=xxx;dbname=[xxx]";
$username = "[xxx]";
$password = "[xxx]";
$pdo = new PDO($dsn, $username, $password);
$rows = array();
if(isset($_GET['Town'])) {
$stmt = $pdo->prepare("SELECT rsTown FROM pubs WHERE name = ?");
$stmt->execute(array($_GET['rsTown']));
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
}
if(isset($_GET['County'])) {
$stmt = $pdo->prepare("SELECT rsCounty FROM pubs WHERE name = ?");
$stmt->execute(array($_GET['rsCounty']));
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
}
echo json_encode($rows);
?>
Please help