简体   繁体   English

如果输入了最低价格,如何要求最高价格?

[英]How to make max price be required if min price entered?

So basically it works like person inputs min price (but forgets to input max price) then he presses search (it won't search and a wording comes out beside the max price that asks him to input max budget..... 因此,基本上,它的工作原理类似于用户输入最低价格(但忘记输入最高价格),然后按搜索(不会进行搜索,并且在最高价格旁边出现一个措辞,要求他输入最高预算。

<form role="search" id="myform1" name="form" method="get" action="<?php echo home_url( '/properties/' ); ?>" >
    <div class="mini-field" id="minfield">
        <input input name="pricefrom" class="txt-field-input-mini formattingNumber" placeholder="Price from" style="width:159px;"id="min">
        <p><input input name="priceto" class="txt-field-input-mini formattingNumber" placeholder="Price to" title="Please input maximum price budget" style="width:159px;" id="max"></p>
    </div>
    <button type="submit" class="start-search-btn" id=search>Start Search<img src="<?php echo get_template_directory_uri();?>/images/search-img-white.png"  alt="Start Search" class="start-search-img"/></button>
</form>

Set the Conditions like these:- 设置以下条件:

`if ($("#min").val()== ""){
    /*Do Your Search*/
}
else{
    if($("#min").val()!== "" && $("#max").val()!==""){
        /*Do Your Search*/ 
    }
}`

Update your code like this:- 像这样更新代码:

$(document).ready(function(){
   $("#myform1").submit(function(event){
       if ($("#min").val()== "" ){
          /*Do Your Search*/
       }
       else{
          if($("#min").val()!== "" && $("#max").val()!==""){
              /*Do Your Search*/ 
          }
          else{event.preventDefault();//this doesn't allow submit function to execute
              alert("Please Fill the details");
          }
       }
   });

Since you are triggering a 'submit' event, you MUST cancel it if you don't want the form to submit. 由于您正在触发“提交”事件,因此如果您不想提交表单,则必须取消它。 (Building on Gaurav Kalyan's answer) (基于Gaurav Kalyan的答案)

<script> 
$(document).ready(function() { 
    $('#myform1').on('submit', function(e) {

        // If min value is set but NO max value is set, cancel the submit
        if ($('#min').val() && !$('#max').val()) { 
            e.preventDefault(); // Cancel the default event of submitting the form
            alert("fill details; return false"); 
        } 
    }); 
}); 
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 最低价格和最高价格以reactjs形式进行验证 - min price and max price validation in reactjs form 具有最低和最高价格的表单字段 - Form field with Min and Max price 根据最低和最高价格过滤JSON数据 - Filtering JSON Data based on Min and Max Price 如何在此PHP页面中使用简单的HTML选择替换此价格滑块? 选择选项可以传递2个值(最小和最大价格)吗? - How can I replace this price slider with a simple HTML select in this PHP page? Can the select option pass 2 values (min and max price)? 如何将选定的最高和最低价格值传递给html中select标签内的Java脚本函数? - How to pass the selected max and min price value to java script function inside of select tag in html? 使用reactJS创建价格范围字段(最小和最大) - Create price range fields (min and max) using reactJS 最小最大价格范围验证不适用于jquery.validate.js - min max price range validation not working with jquery.validate.js 价格过滤器(最低和最高价格),带有一个下拉菜单,asp.net核心 - Price filter (min and max price) with a dropdown menu asp.net core 如果销售价格 = 正常价格,如何不显示正常价格 - How to not get regular price to show if sale price = regular price 如何在网上商店销售价格上设计价格颜色 - How to style price color on webshop sale price
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM