简体   繁体   English

如果表单选项值选择等于然后重定向PHP / jQuery

[英]If form option value select equals then redirect PHP/jQuery

I have a form on my page with a dropdown of counties. 我的页面上有一个表格,下拉各州。 I want to somehow, with jQuery or PHP say that if a certain county is selected then redirect otherwise process the form. 我想以某种方式,用jQuery或PHP说如果选择某个县,那么重定向否则处理表单。

I've created a fiddle to try and explain... 我创造了一个小提琴试图解释......

http://jsfiddle.net/KVjAc/ http://jsfiddle.net/KVjAc/

Just submit the form and use a php header command for the values you want to redirect. 只需提交表单并使用php header命令查看要重定向的值。 That would be the first thing to check in the form processor script. 这将是检查表单处理器脚本的第一件事。

No need for javascript unless you are using ajax to refresh parts of the page based on the selection. 除非您使用ajax根据选择刷新部分页面,否则不需要javascript。

Do something like: 做类似的事情:

$(document).ready(function () {
    $('#county').on('change', function () {
        var value = $(this).val();
        if (value == 'cheshire' || value == 'city of london' || value == 'durham') {
            window.location.href = 'http://www.google.com/';
        }
    })
});

EDIT: Also, you need to add values to your option elements: <option value="cheshire">Cheshire</option> 编辑:此外,您需要为选项元素添加值: <option value="cheshire">Cheshire</option>

I hope this helps(if you need a javascript/jquery solution), 我希望这有帮助(如果你需要一个javascript / jquery解决方案),

$('#selectbox_ID').change( function() {
     if($(this).val() == "your country"){

     }
});

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM