我使用带选项的select标签创建了一个搜索表单。我想使用选中的每个选项提交到搜索查询。我正在使用Wordpress。以下是我的表格:
function categories_header_form()
{
?>
<div id="header-form">
<h3 class="form-title">
<?php echo 'Αναζήτηση προϊόντων ανά περιοχή' ?>
</h3>
<form id="search-form" action="<?php bloginfo('url'); ?>" method="get" >
<div class="form-container">
<?php nomoi(); ?>
<?php products_selection(); ?>
<button type="submit" class="button" id="search-form-button">Εύρεση</button>
</div>
</form>
</div>
<?php
}
选择下拉列表的两个函数:
function products_selection()
{
$args = array(
'post_type' => 'seller',
'taxonomy' => 'category',
'hide_empty' => 0,
'exclude' => 1,1078,1079
);
$products = get_categories( $args );
if ( $products ) {
echo '<select id="products-select">';
echo '<option selected="" disabled="" value="0"><span>Προϊόντα</span></option>';
foreach ($products as $product) {
echo '<option class="product-name" id="'. $product->term_id .'">'. $product->name .'</option>';
}
echo '</select>';
}
}
function nomoi()
{
$args = array(
'post_type' => 'seller',
'taxonomy' => 'nomos',
'hide_empty'=> 0,
'parent' => 0
);
$categories = get_categories( $args );
if ( $categories ) {
echo '<select id="nomoi-select" name="nomoi">';
echo '<option selected="selected" disabled="disabled"><span>Νομοί</span></option>';
foreach ( $categories as $category ) {
$id = $category->term_id;
$name = $category->name;
echo '<option class="nomos" id="'. $id .'">'. $name .'</option>';
}
echo '</select>';
echo '<select id="towns-select" name="towns">';
echo '<option class="town-disabled" selected="selected" disabled="disabled"><span>Πόλεις</span></option>';
echo '</select>';
}
}
答案 0 :(得分:0)
使用Jquery,您可以在用户更改选择字段时提交表单。
$('select').change(function ()
{
$(this).closest('form').submit();
});