Denoteone
Denoteone

Reputation: 4055

Use JavaScript to redirect form plugin on submit

I need help trying to redirect a wordpress form plugin when the user clicks submit. I can add javascript to the form in where I check the value of a radio button and redirect based on that. Below is the code I am trying to add. Below that is the error I am seeing in 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/'};"

Error:

SyntaxError: unterminated string literal


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

Upvotes: 0

Views: 120

Answers (2)

Azeem Hassni
Azeem Hassni

Reputation: 886

here is a jQuery solution .

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";
          } 
    })

});

Upvotes: 1

Arielle Lewis
Arielle Lewis

Reputation: 540

Unless I'm going blind you're missing ( and ) around your if statement. Give this a shot:

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/'};"

Upvotes: 1

Related Questions