如果未选择下拉列表,则在提交时不发送 GET 变量 [英] Not send GET variable on submit if dropwdown not selected

查看:33
本文介绍了如果未选择下拉列表,则在提交时不发送 GET 变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表单,用于过滤仅包含下拉列表的搜索结果.我使用 GET 而不是发布,以便可以轻松地与 URL 共享结果.

I have a form that I used to filter search results that consist of only dropdowns. I use GET rather then post so that the results can easily be shared with the URL.

    <form action="" name='filter' method="GET">
      <select name="Make" id="Make">
          <option selected="selected" value ="nothing">All</option>             
          <option  value="Toyota">Toyota</option>           
          <option value="Honda">Honda</option>
      </select>
      <input type="submit" value="Filter">
    </form>

就像现在一样,如果用户不更改选择,它将为 get 变量 Make 提交值nothing".它们是多个下拉菜单,与模型年份等相同.

As it is right now if It will submit the value "nothing" for the get variable Make if the user doesn't change the selection. They're are multiple drop downs identical as this one for model year etc.

如果没有使用 Make 变量,是否有可能不显示在 URL 中?

Is it possible for the Make variable to not show up in the URL if it isn't used?

现在,如果提交该代码,它会显示 website.com/?Make=nothing.我尝试删除该值,然后显示 website.com/?Make=All.如果选择了全部",我不想让 make 显示在 URL 中.这可能吗?

As it is now if that code is submited it will say website.com/?Make=nothing. I tried removing the value and then it says website.com/?Make=All. I do not want make to show up in the URL if "All" is selected. Is this possible?

推荐答案

您没有 submit 按钮 :)
你可以添加一个在提交时运行的 JS 并检查 "Make" 的值,如果它是 "nothing" 只需做一个简单的重定向而不是提交表单.类似的东西:

You don't have a submit button :)
you can add a JS that runs on submit and checks the value of "Make" and in case it's "nothing" just do a simple redirect instead of submitting the form. Something like:

var e = document.getElementById("Make");
var val = e.options[e.selectedIndex].value;
if (val === 'nothing'){
  window.location = "http://www.google.com/"
}

这篇关于如果未选择下拉列表,则在提交时不发送 GET 变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆