想根据单选按钮值重定向用户

时间:2018-05-03 16:52:43

标签: javascript

我正在尝试将字符串附加到说明字段,并根据用户选择单击的单选按钮重定向用户。在这种情况下,客户点击" Cleardent Customer"单选按钮,在提交时,应在描述字段中附加一个字符串,并将其指向特定页面。

这是一个演示页面,我试图弄清楚用户是回头客还是新客户。

我尽力编写代码,但似乎我犯了很多错误。它没有将值传递给描述字段,也没有正确地重定向等。

这是我的代码



  $("#sfdemoPreSubmit").click(function(e) {
    e.preventDefault();
    $("#sfcompany").val($("#sflast_name").val() + ", " + $("#sffirst_name").val());
    $("#sfphone").val(cleanPhNum($("#sfphone").val()));
    $("#sfstate").val(getProvince($("#sfphone").val()));
    $("#sfdescription").val($("sfdescription").val() + $("input[name=source]:checked").val());
    $("#sfDemoForm").validate();
    if ($("#sfDemoForm").valid()) {
       grecaptcha.execute();
    }
  });

 function redirect() {
    var province = $('#sfstate').val();
    var customerCategory = $('input[name=source]:checked').val();
    if (customerCategory == 'cleardent customer') {
      $("#retURL").val("https://cleardent.com/demo/demo-thankyou-existing.html");
    }
      else if (province == 'BC') {
      $("#retURL").val("https://cleardent.com/demo/demo-thankyou-bc.html");
    } else if (province == 'ON')  {
      $("#retURL").val("https://cleardent.com/demo/demo-thankyou-on.html");
    } else if (province == 'AB') {
      $("#retURL").val("https://cleardent.com/demo/demo-thankyou-ab.html");
    } else {
      $("#retURL").val("https://cleardent.com/demo/demo-thankyou-default.html");
    }  
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="row"> 
          <div class="col-md-6 col-md-offset-3"> 
            <form id="sfDemoForm" action="https://webto.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="POST" class="sky-form">
              <input name="captcha_settings" value="{&quot;keyname&quot;:&quot;IC_ClearDent_Main_Demo&quot;,&quot;fallback&quot;:&quot;true&quot;,&quot;orgId&quot;:&quot;00D1I0000002QyG&quot;,&quot;ts&quot;:&quot;&quot;}" type="hidden">
              <input name="oid" value="00D1I0000002QyG" type="hidden">
              <input name="retURL" id="retURL" value="https://test.cleardent.com/demo-thankyou-bc.html" type="hidden">             
              <fieldset>
                <label class="input margin-bottom-15"><i class="icon-prepend fa fa-user"></i>
                  <input  id="sffirst_name" maxlength="40" name="first_name" size="20" type="text" required placeholder="First name">
                </label>
                <label class="input margin-bottom-15"><i class="icon-prepend fa fa-user"></i>
                  <input  id="sflast_name" maxlength="80" name="last_name" size="20" type="text" required placeholder="Last name">
                </label>
                <label class="input margin-bottom-15"><i class="icon-prepend fa fa-envelope"></i>
                  <input id="sfemail" maxlength="80" name="email" size="20" type="email" required placeholder="Email address">
                </label>
                <!-- <label class="label" for="phone">Phone</label>-->
                <label class="input margin-bottom-25"><i class="icon-prepend fa fa-phone"></i>
                  <input id="sfphone" maxlength="40" name="phone" size="20" type="text" required placeholder="Phone">
                </label>
              <div class="radio-button">
                <input class="form-check-input" type="radio" name="source" id="inlineRadio1" value="new customer">
                <label class="form-check-label" for="inlineRadio1">New Customer </label>
    
    
                <input class="form-check-input" type="radio" name="source" id="inlineRadio2" value="cleardent customer">
                <label class="form-check-label" for="inlineRadio2">ClearDent Customer </label>
    
    
                <input class="form-check-input" type="radio" name="source" id="inlineRadio3" value="other3">
                <label class="form-check-label" for="inlineRadio3">Other </label>
             </div> 
             <!--<label class="label" for="description">Notes</label>-->
                <label class="textarea textarea-resizable margin-bottom-25">
                  <textarea id="sfdescription" name="description" placeholder="Is there something specific you want to see from ClearDent?"></textarea>
                </label>
                <input id="sfstate" name="state" type="hidden">
                <input id="sflead_source" name="lead_source" type="hidden" value="Website">
                <input id="sfcompany" name="company" type="hidden">
                <input id="sfCampaign_ID" name="Campaign_ID" type="hidden" value="7011I000000d5auQAA">
              </fieldset>
              <div id="recaptcha" class="g-recaptcha" data-sitekey="6LeXmEAUAAAAAG7VJd6Z8YCVkP44AgAlqCUmpRAi" data-callback="submitDemoToLead" data-size="invisible"> </div>
              <footer>
                <button id="sfdemoPreSubmit" class="btn-u"><i class="fa fa-paper-plane fa-fw"></i> Get Your Free Demo</button>
              </footer>
            </form>
          </div>
        </div>
&#13;
&#13;
&#13;

非常感谢你!请让我知道,如果你有任何问题。

0 个答案:

没有答案