Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/442.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_Forms_Redirect_Wordpress - Fatal编程技术网

在提交时使用JavaScript重定向表单插件

在提交时使用JavaScript重定向表单插件,javascript,forms,redirect,wordpress,Javascript,Forms,Redirect,Wordpress,我需要帮助,试图重定向wordpress表单插件时,用户点击提交。我可以将javascript添加到表单中,在表单中检查单选按钮的值并基于该值重定向。下面是我试图添加的代码。下面是我在firebug中看到的错误 Javascript: on_sent_ok: "if (document.getElementByName('review_stars').value=='4')||(document.getElementByName('review_stars').value=='5') {loca

我需要帮助,试图重定向wordpress表单插件时,用户点击提交。我可以将javascript添加到表单中,在表单中检查单选按钮的值并基于该值重定向。下面是我试图添加的代码。下面是我在firebug中看到的错误

Javascript:

on_sent_ok: "if (document.getElementByName('review_stars').value=='4')||(document.getElementByName('review_stars').value=='5')
{location = 'http://74.208.11.118:8085/review-submission/'} else { location = 'http://74.208.11.118:8085/review-thank-you/'};"
错误:

SyntaxError: unterminated string literal


"if (document.getElementByName('review_stars').value=='4')||

除非我瞎了眼,否则你会错过你的if声明。试一试:

on_sent_ok: "if (document.getElementByName('review_stars').value=='4' || document.getElementByName('review_stars').value=='5'){location = 'http://74.208.11.118:8085/review-submission/'} else { location = 'http://74.208.11.118:8085/review-thank-you/'};"

下面是一个jQuery解决方案

jQuery(document).ready(function($){
    var myform = $("#my_form_id");
    myform.submit(function(e){
        e.preventDefault();
        s = $("[name='review_stars']:checked");
          if(s.val() == 1) {
              window.location = "http://somedomain.com";
          } else if(s.val() == 2) {
              window.location = "http://anotherdomain.com";
          } 
    })

});

谢谢你,明白了。不知道我为什么用那种方式使用“()”。