如果没有选择dropwdown,则不会在提交时发送GET变量 [英] Not send GET variable on submit if dropwdown not selected

查看:138
本文介绍了如果没有选择dropwdown,则不会在提交时发送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变量提交值nothingMake if用户不更改选择。它们是与模型年等相同的多个下拉列表。

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。如果选择了全部,我不希望在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?

推荐答案

你没有一个提交 :)

您可以添加一个运行在提交的JS,并检查Make的值,如果它是没有什么只是做一个简单的重定向,而不是提交表单。如下:

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/"
}

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

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