如何选择选项时如何重定向页面,laravel

发布于 2025-02-07 17:16:03 字数 769 浏览 3 评论 0原文

选择选项之一时,我需要重定向页面。

<select required name="subject"  id="konu" class="form-control">
  <option value="" disabled>Choose Subject</option>
  <option value="Ask a question">Ask a question</option>
  <option value="Leave a comment">Leave a comment</option>
  <option value="Where to buy">Where to buy</option>
  <option value="Product Complaint">Product Complaint</option>
  <option value="Other">Other</option>
  <option {{ request('subject') == 'Request SDS' ? 'selected' : '' }}  value="Request SDS">Request SDS</option>
  <option value="Distributor">Request Distributorship</option>
</select>

I need to redirect page when one of the option is selected.

<select required name="subject"  id="konu" class="form-control">
  <option value="" disabled>Choose Subject</option>
  <option value="Ask a question">Ask a question</option>
  <option value="Leave a comment">Leave a comment</option>
  <option value="Where to buy">Where to buy</option>
  <option value="Product Complaint">Product Complaint</option>
  <option value="Other">Other</option>
  <option {{ request('subject') == 'Request SDS' ? 'selected' : '' }}  value="Request SDS">Request SDS</option>
  <option value="Distributor">Request Distributorship</option>
</select>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

节枝 2025-02-14 17:16:03

我曾经也需要这个,发现您的问题已经得到回答。

如果您可以使用Inline JavaScript,请查看以下答案:
https://stackoverflow.com/a/7562129/10440010

同样的问题:
https://stackoverflow.com/a/7562201/10440010

我希望这会有所帮助!

更新:

使其适用于特定选项的简便方法是使Onchange事件检查点击选项的值是否等于某物。在下面的摘要中,我使其适用于以https开头的所有链接。

HTML:

<select id="redirectSelect">
    <option value="NoLink" disabled>Please select</option>
    <option value="NoLinkEither">Option 1</option>
    <option value="https://www.google.com/">External Link</option>
</select>

JavaScript:

function redirect(goto) {
  var conf = confirm("Are you sure you want to go elswhere?");
  if (conf && goto != '') {
    window.location = goto;
  }
}

var selectEl = document.getElementById('redirectSelect');

selectEl.onchange = function() {
  if (this.value.startsWith('https')) {
    var goto = this.value;
    redirect(goto);
  }
};

希望这可以帮助您解决问题。如果没有,请发表评论,我很高兴提供帮助!

I once needed this too and found that your question has already been answered.

If you're fine with using inline JavaScript, check out this answer:
https://stackoverflow.com/a/7562129/10440010

If you prefer staying off of inline, check out this answer under the same question:
https://stackoverflow.com/a/7562201/10440010

I hope this helps!

Update:

An easy way of making it work for specific options, is to make the onChange event check whether the value of the clicked option equal to something. In the snippet below, I make it work for all links starting with HTTPS.

HTML:

<select id="redirectSelect">
    <option value="NoLink" disabled>Please select</option>
    <option value="NoLinkEither">Option 1</option>
    <option value="https://www.google.com/">External Link</option>
</select>

JavaScript:

function redirect(goto) {
  var conf = confirm("Are you sure you want to go elswhere?");
  if (conf && goto != '') {
    window.location = goto;
  }
}

var selectEl = document.getElementById('redirectSelect');

selectEl.onchange = function() {
  if (this.value.startsWith('https')) {
    var goto = this.value;
    redirect(goto);
  }
};

Hopefully this helps you enough to solve your problem. If not, leave a comment and I am glad to help!

送舟行 2025-02-14 17:16:03

我先前有一个代码。

<select required name="subject" id="konu" class="form-control">
                                <option value="" disabled>Choose Subject</option>
                                <option value="Ask a question">Ask a question</option>
                                <option value="Leave a comment">Leave a comment</option>
                                <option value="Where to buy">Where to buy</option>
                                <option value="Product Complaint">Product Complaint</option>
                                <option value="Other">Other</option>
                                <option {{ request('subject') == 'Request SDS' ? 'selected' : '' }}  value="Request SDS">Request SDS</option>
                                <option value="Distributor">Request Distributorship</option>
                            </select>

在这里选择它是脚本。

$( document ).ready(function() {
        $("#konu").change(function(){
                var value = $("#konu").val();
                if(value=="distributor"){
                    window.location = 'be-our-distributor';
                }
            })
        });

I have a code previously woked.Here is select

<select required name="subject" id="konu" class="form-control">
                                <option value="" disabled>Choose Subject</option>
                                <option value="Ask a question">Ask a question</option>
                                <option value="Leave a comment">Leave a comment</option>
                                <option value="Where to buy">Where to buy</option>
                                <option value="Product Complaint">Product Complaint</option>
                                <option value="Other">Other</option>
                                <option {{ request('subject') == 'Request SDS' ? 'selected' : '' }}  value="Request SDS">Request SDS</option>
                                <option value="Distributor">Request Distributorship</option>
                            </select>

Here it is script.

$( document ).ready(function() {
        $("#konu").change(function(){
                var value = $("#konu").val();
                if(value=="distributor"){
                    window.location = 'be-our-distributor';
                }
            })
        });
一身仙ぐ女味 2025-02-14 17:16:03

对于第二个答案,HTML中使用的值与您在JavaScript代码中检查的值不同。

在您的html中,它是distributor,在您的JavaScript代码中,它是Distributor。介意首都D。

For the second answer, the value used in your HTML differs from the value you're checking against in the JavaScript code.

In your HTML, it's Distributor and in your JavaScript code it's distributor. Mind the capital D.

木格 2025-02-14 17:16:03

问题处于您的状况。您的价值是分销商,您使用分销商。 JS是案例感觉的,因此您不会重定向。代码应该看起来像

$( document ).ready(function() {
    $("#konu").change(function(){
            var value = $("#konu").val();
            if(value=="Distributor"){
                window.location = 'be-our-distributor';
            }
        })
    });

the problem is on your condition. Your value is Distributor and u using distributor. Js is case sensetive so you not getting any redirection. the code should look like

$( document ).ready(function() {
    $("#konu").change(function(){
            var value = $("#konu").val();
            if(value=="Distributor"){
                window.location = 'be-our-distributor';
            }
        })
    });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文