我正在使用我在其中使用表单的过滤器。当用户登陆列表页面时,它应该自动提交表单,以便用户只能获得他想要查看的值。我已经尝试了很多东西,比如jquery JS和在体内使用片段,但它们都没有用。对于以下代码,表单将继续提交。
<div class="container shop-filter">
<div class="filter">
<form action="" method="POST" enctype="multipart-form-data" id="city-filter" name="cit-filter">
<select name="filter" id="select">
<option value="all">All city</option>
<?php
$sql="SELECT * FROM tcity";
$connect= mysqli_query($conn, $sql) or die ("Failed To Connect.");
while($rows= mysqli_fetch_array($connect, MYSQLI_ASSOC)){ ?>
<option value= "<?php echo $rows['c_id']?>" id="optin_val" <?php echo (!empty($_COOKIE['dropdown']) && $_COOKIE['dropdown'] == $rows['c_id'] ? 'selected' : ''); ?>><?php echo $rows['city_nm'];?></option>
<?php }
?>
</select>
<input type="submit" name="submitt" id="submitt" value="filter" class="btn .btn-default">
</form>
</div>
<div class="view">
<a href="#" id="grid" class="switcher active"><i class="fa fa-th fa-lg" aria-hidden="true"></i><span id="grid-view"> Grid</span></a>
<a href="#" id="list" class="switcher"><i class="fa fa-th-list fa-lg" aria-hidden="true"></i><span id="list-view"> list</span></a>
</div>
<hr id="hr-1" style="width:100%">
</div>
<div class="container blocks" id="content">
<?php
//Grab the variable sent through link by sub_category.php
//session_start();
$subcategory_id='';
$subcategory_id= $_GET['sub_id'];
$_SESSION['sub'] = $subcategory_id;
$row_count = 0;
if(isset($_POST['submitt'])){
$city_id=$_POST['filter'];
if($city_id == 'all'){
$sql="SELECT * FROM tadd WHERE sub_id = '$subcategory_id' ORDER BY add_nm";
}else{
$sql="SELECT * FROM tadd WHERE sub_id = '$subcategory_id' AND c_id = '$city_id' ORDER BY add_nm";
}
}else{
$sql="SELECT * FROM tadd WHERE sub_id = '$subcategory_id' ORDER BY add_nm";
}
//$sql="SELECT * FROM tadd WHERE sub_id = '$subcategory_id' AND c_id = '$city_id'";
$conection = mysqli_query($conn, $sql);
while ($rows = mysqli_fetch_array($conection, MYSQLI_ASSOC)){
$name = $rows['add_nm'];
$add_id = $rows['add_id'];
//get the join date and Expiry date to hide Expired Contents
$current_date = strtotime(date('Y-m-d'));
$exp = strtotime($rows['exp_dt']);
$row_count = mysqli_num_rows($conection);
//get Images
//$shop_image = trim($add_id.'.jpg');
?>
<!-- Do Not Show Expired Contents -->
<?php if( $current_date <= $exp ) {?>
<div class="dialog">
<div class="shop_img">
<img src="../image/shops/1.jpg" alt ="<?php echo $name;?>" >
</div>
<hr id="hr">
<div class="shop_name">
<?php echo strtoupper($name);?>
</div>
<a href="detail.php?add=<?php echo $add_id;?>"><div class="address">
<span id="1">ADDRESS</span><span id="2"><i class="fa fa-arrow-right" aria-hidden="true"></i></i></span>
</div></a>
</div>
<?php
}
}
if( $row_count == 0 ){
echo '<div class ="msg">Sorry! No Entries Found.</div>';
}
?>
</div>
</body>
<footer>
<?php
include("../footer.html");
?>
</footer>
<script>
$(document).ready(function(){
$("#city-filter").submit();
})
</script>
正如我在图片中所示,当用户访问此页面时,它必须仅显示成功类。但它显示所有...当我热过滤它时会显示currect.so我想取消手动提交提交并自动提交表格
答案 0 :(得分:2)
您可以将其置于条件中以检查是否存在一些<html>
<head>
<title>Dartverein XY</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<a href="index.php" id="headerLink">
<section id="header">
<div id="title">Steeldartverein<br>Mühldorf e.V.</div>
</section>
</a>
<div class="horizontalBorder"></div>
<section class="menu">
<p class="verticalBorder"></p>
<a href=""><div tabindex="0" class="menuElementRed">News</div></a>
<p class="verticalBorder"></p>
<a href="">Über uns</a>
<p class="verticalBorder"></p>
<a href=""><div class="menuElementRed">Weiteres</div></a>
<p class="verticalBorder"></p>
<a href=""><div class="menuElementGreen">Login</div></a>
<p class="verticalBorder"></p>
<p class="lastVerticalBorder"></p>
</section>
<div class="horizontalBorder"></div>
</body>
</html>
div:
dialog
而是使用$(document).ready(function(){
if($('.dialog').length === 0 ){ // check the length of dialog div if 0
$("#city-filter")[0].submit(); // then only submit the form
}
})
上的原生.submit()
事件。