Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
基于无线电选择的Javascript重定向_Javascript_Html_Redirect_Cpanel - Fatal编程技术网

基于无线电选择的Javascript重定向

基于无线电选择的Javascript重定向,javascript,html,redirect,cpanel,Javascript,Html,Redirect,Cpanel,我已经设计了这个脚本,根据无线电选择重定向到特定页面,但它会继续转到设置的旧链接。你有什么建议可以让这项工作顺利进行吗 <div class="col-12" style="margin-top"> <label><strong>What Is Your Business Currently Generating?</strong></label> <div

我已经设计了这个脚本,根据无线电选择重定向到特定页面,但它会继续转到设置的旧链接。你有什么建议可以让这项工作顺利进行吗

            <div class="col-12" style="margin-top">
            <label><strong>What Is Your Business Currently Generating?</strong></label>
            <div class="d-flex m-t--20">
                <div class="p--relative check">
                    <input type="radio" id="o5kradio" name="income" value="o5k" checked required/>
                    <label for="diy">Over $5k Per Month</label>
                </div>
                <div class="p--relative check">
                    <input type="radio" id="u5kradio" name="income" value="u5k" required/>
                    <label for="hands-on">Under $5k Per Month</label>
                </div>
            </div>
        </div>



        <script>
        var o5kradio = document.getElementById("o5kradio"),
        u5kradio = document.getElementById("u5kradio"),
        submitButton = document.getElementById("SubmitButton");

         submitButton.addEventListener("click", function () {
         if (o5kradio.checked) {
         alert('o5k');
         window.location = "https://vincedelmonte7figuremastermind.com/sit-in/schedule-now/";
         } else {
         alert('u5k');
         window.location = "https://vincedelmonte7figuremastermind.com/sit-in/schedule-now-2/";
    }
    }, false);
    </script>

        <!--ERROR/SUCCESS MESSAGE-->
        <div class="message js-message"></div>
        <button type="submit" value="submit" id="SubmitButton" class="btn txt--shadow-smaller">Click TO SUBMIT APPLICATION</button>
    </form>

您的业务目前产生了什么?
每月超过5000美元
每月低于5000美元
var o5kradio=document.getElementById(“o5kradio”),
u5kradio=document.getElementById(“u5kradio”),
submitButton=document.getElementById(“submitButton”);
submitButton.addEventListener(“单击”,函数(){
如果(O5K无线电,已检查){
警报(“o5k”);
window.location=”https://vincedelmonte7figuremastermind.com/sit-in/schedule-now/";
}否则{
警报(“u5k”);
window.location=”https://vincedelmonte7figuremastermind.com/sit-in/schedule-now-2/";
}
},假);
点击提交申请

无论选择什么,都会将用户发送到此处:

好的,这样做很有效,虽然有点过分,但非常彻底的过分,您可以将其用于任何未来的单选按钮表单,即使是具有几十个选项的表单:

      <div class="col-12" style="margin-top">
        <label><strong>What Is Your Business Currently Generating?</strong></label>
        <div class="d-flex m-t--20">
            <div class="p--relative check">
                <input type="radio" id="o5kradio" name="income" value="o5k" checked required/>
                <label for="diy">Over $5k Per Month</label>
            </div>
            <div class="p--relative check">
                <input type="radio" id="u5kradio" name="income" value="u5k" required/>
                <label for="hands-on">Under $5k Per Month</label>
            </div>
        </div>
    </div>

  <script>
    // No need for declaring global variables here
    function submit(source,options){
    // First, this segment finds the checked element in the array:
      for (var i = 0; i < options.length; i++){
        if (options[i].checked){
          break;
        }
      }
    // Next, the source switch determines which button element called the function:
    switch(source.id){  
   case 'submitButton':
    // The options switch then determines what happens when the checked option is submitted:
      switch(options[i].id){
        case 'o5kradio':
          alert('over5k');
          window.location = "https://vincedelmonte7figuremastermind.com/sit-in/schedule-now/";
          break;
        case 'u5kradio':
          alert('under5k');
          window.location = "https://vincedelmonte7figuremastermind.com/sit-in/schedule-now-2/";
          break;
          //  The default option for the options switch
        default:
          window.location = "https://vincedelmonte7figuremastermind.com/sit-in/schedule-now/";
          }
        break;
        // The default option for the source switch
        default:
       }
    }
</script>

    <!--ERROR/SUCCESS MESSAGE-->
    <div class="message js-message"></div>
    <button type="submit" value="submit" id="submitButton" onclick="submit(this,options=[o5kradio,u5kradio])" class="btn txt--shadow-smaller">Click TO SUBMIT APPLICATION</button>
</form>
再说一次,这太过分了,如果我在这里至少犯了一个错误,我也不会感到惊讶,但这种设置的美妙之处在于,您拥有的每个单选按钮表单都可以使用相同的功能,并且您可以拥有任意多的选项

每次用户单击“提交”按钮(我想是在其他页面上)时,您只需在“source.id”开关中添加另一个“case”,您就可以控制一个功能可能拥有的页面、重定向和选项的数量。这意味着每次单击将只进行三次计算(针对语句、源开关和选项开关),以避免一行中有多个“else-if”语句用于两个以上的单选按钮


PS.“submitButton”的Id以大写字母“S”开头,但我无法解决此问题。

以下是一种基于单选按钮选择实现页面重定向的方法:

const incomeRadioButtons=document.querySelectorAll('[name=“income”]');
incomeRadioButtons.forEach((单选按钮)=>{
radioButton.onchange=函数(){
window.location.href=window.location.href+radioButton.dataset.url;
}
});
.default{
显示:无;
}

您的业务目前产生了什么?
违约
每月超过5000美元
每月低于5000美元

如果我给了你一个不使用javascript的解决方案,这对你有好处吗?你能使用jQuery吗?还是这仅仅是javascript?
<button type="submit" value="submit" id="submitButton" onclick="submit(this,options=[o5kradio,u5kradio])" class="btn txt--shadow-smaller">Click TO SUBMIT APPLICATION</button>
function submit(source,options){
  for (var i = 0; i < options.length; i++){
    if (options[i].checked){
      break;
    }
  } ...etc.
 // The source switch  
    switch(source.id){  
   case 'submitButton':
      // The options switch, currently the first "case" of the source switch, but you can add as many cases as needed
      switch(options[i].id){
        case 'o5kradio':
          alert('over5k');
          window.location = "https://vincedelmonte7figuremastermind.com/sit-in/schedule-now/";
          break;
        case 'u5kradio':
          alert('under5k');
          window.location = "https://vincedelmonte7figuremastermind.com/sit-in/schedule-now-2/";
          break;
          //  The default option for the options switch
        default:
          window.location = "https://vincedelmonte7figuremastermind.com/sit-in/schedule-now/";
          }
        break;
        // The default option for the source switch
        default:
       }