我是 jQuery 的新手,但这就是我想要做的。
我有一个名为 City 和 Zip 的多选字段的表单,
我正在尝试获取此选择字段的值并将其与我拥有的城市列表进行比较,如果发现任何匹配项,jQuery 将使用这些值更新名为 city 的隐藏文本字段的值,然后提交表单。如果没有找到匹配项,他们将被重定向到不同的网站。
与邮政编码相同,它将从同一字段中获取邮政编码,并查看它是否与列表中的任何邮政编码匹配。如果是,则更新邮政编码隐藏字段,如果不是,则将它们重定向到另一个网站。
这是我现在的代码,它不工作。
$("#front-form").submit(function(event) {
// Getting the values from the HTML select field
var CityandZip = $("#citynzip").val();
//Comparing the values with the cities list
if (CityandZip === "City 1" || "City 2" || "City 3") {
//Updaing the hidden field and submitting
$("#HiddenCityField").val(CityandZip);
//Comparing the values with the ZIP code list
} else if (CityandZip === "11111" || "11112" || "11113") {
//Updating the hidden ZIP code field
$("#HiddenZipField").val(CityandZip);
} else {
//Redircting to a new site
window.location.href = "http://www. redirecttowebsite.com";
}
});
任何帮助将不胜感激,并在此先感谢。