如果/ Else表格的邮政编码/县过滤器 [英] If/Else Form For Zip Code/County Filter

查看:133
本文介绍了如果/ Else表格的邮政编码/县过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站,其中包含我所居住地区某些县的特定内容。我想创建一个表单,帮助用户访问他们需要的特定页面。因为我不想要一个县的下拉列表。我希望用户输入邮政编码,如果该邮政编码内有重叠,则选择一个县。

I have a website that has specific content for certain counties in the region where I live. I want to create a form that will help the user get to the specific page they need. Because I don't want a dropdown list of counties. I want the user to enter the zipcode, and then choose a county if there is an overlap within that zipcode.

我不确定这是否可行,但我我正在尝试创建一个表单来执行此操作:

I'm not sure if this is possible, but I am trying to create a form that will do this:

表单的第一部分:输入邮政编码的文本框,然后单击提交,然后显示隐藏的显示无线电组选项对于可用的县,根据他们选择的县,他们会被定向到特定的网址。

First Part of Form: Textbox to enter Zip Code, then click Submit, then show a hidden to Show Radio Group Option for available Counties, depending on which county they select, they get directed to a specific URL.

我正在尝试将其基于我在小提琴

I'm trying to base it on this code I saw on Fiddle

这是我正在使用的(并且失败了) with)

Here is what I am using (and failing with)

<form  id="zip_form">
Zip Code: <input type="text" name="zipcode" id="id_zip_code"/><input type="submit"    
value="Submit"/>
</form>

<div id="id_div_one">Option County1, County2 or Other</div>

<div id="id_div_two">Option County3, County4 or Other</div>    

<div id="id_div_sorry">Please call our office for a quote</div>

jQuery:

$(function () {
var zipCode1 = ['11111', '22222', '33333'];
$('#id_div_one, #id_div_sorry').hide();

var zipCode2 = ['44444', '55555', '66666'];
$('#id_div_two, #id_div_sorry').hide();

$('#zip_form').submit(function () {
    $('#id_div_one, #id_div_two, #id_div_sorry').hide();
    if (jQuery.inArray($('#id_zip_code').val(), zipCode1) > -1) {
        $('#id_div_one').css('display', 'inline');
    }
    if (jQuery.inArray($('#id_zip_code').val(), zipCode2) > -1) {
            $('#id_div_two').css('display', 'inline');
    } else {
            $('#id_div_sorry').css('display', 'inline');
    }
        return false;
    });

});

看到它失败的行动

这可能吗?

谢谢你提前

推荐答案

是的,你的代码几乎可以正常工作。
唯一的错误是,你在第5行覆盖zipCodes数组,因为两个zipCode变量都有相同的名称。

Yes it's possible and your code will almost work. The only fault is, that you overwrite the zipCodes array in line 5, because both zipCode variables have the same name.

所以更改secound的名称zipCode数组,所有都可以。

So change the name of the secound zipCode array and all will work.

var zipCodeOne = ['11111', '22222', '33333'];
$('#id_div_one, #id_div_sorry').hide();

var zipCodeTow = ['44444', '55555', '66666'];
$('#id_div_two, #id_div_sorry').hide();

如需进一步改进,请参阅:

For some further improvements see:

http://jsfiddle.net/E2cMT/4/

这篇关于如果/ Else表格的邮政编码/县过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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