javascriptformspardot

Redirect thank you messages based on conditional form field selects using javascript


I am very new to javascript so this may be easy to some. I am trying to generate a thank you message based on if a visitor selects option "0 to 120,000" AND "option 0 to 6 months". Any help with this is greatly appreciated.

function redirect() {
  var businessrev = document.getElementById("annual_business_revenue");
  var time = document.getElementById("Time")
  for (var i = 0; i < selections.options.length; i++) {
    if ((businessrev.options[i].selected == 1) && (time.options[i].selected == 1)) {
      location.href = "http://www.bing.com";
    } else {
      location.href = "http://www.google.com";
    }
  }
}
<form action="javascript:redirect();">
  <select name="annual_business_revenue">
    <option value="revenue1">0 to 120,000</option>
    <option value="revenue2">NOT 0 to 120,000</option>
  </select>
  <select name="Time">
    <option value="time1">0 to 6months</option>
    <option value="time2">NOT 0 to 6months</option>
  </select>
  <input type="submit" value="Submit" />
</form>


Solution

  • This is what worked for me:

    window.onload=function(){
    var annualRevenue = 'annual_business_revenue';	
    var email = 'email';
    var timeInBusiness = 'Time';
    
    if((timeInBusiness == '0 to 6months' || annualRevenue == '0 to 120,000' )){
    document.location='http://google.com';
    }else{
    document.location='http://bing.com';
    }	
    };
    <select id="annual_business_revenue">
        <option value="revenue1">0 to 120,000</option>
        <option value="revenue2">NOT 0 to 120,000</option>
      </select>
      <select id="Time">
        <option value="time1">0 to 6months</option>
        <option value="time2">NOT 0 to 6months</option>
      </select>
      <input id="goBut" type="button" value="Submit" />