我下面有一个搜索表单,其中有两个选择框和一个文本输入框,用户可以通过关键字进行搜索。但是,无论什么原因,每当我点击关键字文本框时,焦点立即回到了第一个选择框下拉框中的类别,因此我无法在关键字文本框中输入任何内容。有人能看出这是为什么吗?
$categories_list = array();
$ratings_list = array();
try {
$query = $dbh->query("SELECT category, genre, rating FROM posts WHERE 1
GROUP BY category, genre, rating");
$query->setFetchMode(PDO::FETCH_ASSOC);
$iterator = new IteratorIterator($query);
foreach ($iterator as $row) {
if (empty($row['category']) == false && !in_array($row['category'],
$categories_list))
$categories_list[] = $row['category'];
if (empty($row['rating']) == false && !in_array($row['rating'],
$ratings_list))
$ratings_list[] = $row['rating'];
}
} catch (Exception $e) {
echo '<p>', $e->getMessage(), '</p>';
}
?>
<p> </p>
<p> </p>
<h2>Search Completed Stories</h2>
<form name="search" method="get"
action="http://example.com/searchB/">
<label>
Category:
<select name="category">
<?php foreach($categories_list as $category) : ?>
<option><?php echo $category; ?></option>
<?php endforeach; ?>
</select>
</label>
<label>
Rating:
<select name="rating">
<option value="">Any</option>
<?php foreach($ratings_list as $rating) : ?>
<option><?php echo $rating; ?></option>
<?php endforeach; ?>
</select>
</label>
<label>
Keywords:
<input type="text" name="keywords">
</label>
<input type="hidden" name="active" value="0">
<input type="submit"/>