尝试使用onsubmit在注册表单上提交两个函数(已查看其他问题但没有运气)

时间:2015-05-20 10:33:35

标签: javascript html forms onclick onsubmit

我只能分别提交get_action()或checkMandatory()。试图做两件事都不起作用。为了使用get_action我必须使用onClick并使用checkMandatory我必须使用onsubmit。当我使用onClick结合两者时,只有get_action有效。当我尝试使用onsubmit提交两者时,仅checkMandatory正常工作。

以下代码仅触发CheckMandatory。

有人可以帮我修改代码,以便当有人点击提交按钮时它们都会触发吗?

我希望checkMandatory首先触发,然后是get_action,它会根据表单选项将它们引导到正确的位置。

Mailcheck.defaultDomains.push('hp.com', 'yahoo.com.tw', 'yahoo.com.au', 'yahoo.com.mx', 'seznam.cz', 'bellsouth.net', 'hotmail.fr', 'mail.ru', 'btinternet.com', 'cox.net', 'yahoo.com.br', 'bigpond.com', 'yahoo.fr', 'ymail.com', 'earthlink.net', 'xtra.co.nz', 'me.com', 'yahoo.gr', 'walla.com', 'yahoo.es', 'charter.net', 'shaw.ca', 'live.nl', 'yahoo.ca', 'orange.fr', 'optonline.net', 'gmx.de', 'wanadoo.fr', 'optusnet.com.au', 'rogers.com', 'web.de', 'ntlworld.com', 'juno.com', 'yahoo.com.sg', 'rocketmail.com', 'yandex.ru', 'yahoo.co.in', 'centrum.cz', 'live.co.uk', 'sympatico.ca', 'libero.it', 'walla.co.il', 'bigpond.net.au', 'yahoo.com.hk', 'ig.com.br', 'live.com.au', 'free.fr', 'sky.com', 'uol.com.br', 'abv.bg', 'live.fr', 'terra.com.br', 'hotmail.it', 'tiscali.co.uk', 'rediffmail.com', 'aim.com', 'blueyonder.co.uk', 'telus.net', 'bol.com.br', 'hotmail.es', 'email.cz', 'windowslive.com', 'talktalk.net', 'home.nl', 't-online.de', 'yahoo.de', 'telenet.be', '163.com', 'embarqmail.com', 'windstream.net', 'roadrunner.com', 'bluewin.ch', 'skynet.be', 'laposte.net', 'yahoo.it', 'qq.com', 'live.dk', 'planet.nl', 'hetnet.nl', 'gmx.net', 'mindspring.com', 'rambler.ru', 'iinet.net.au', 'eircom.net', 'yahoo.com.ar', 'wp.pl', 'mail.com', 'emmis.com', 'hotmail.de', 'lireo.com', 'gmx.at', 'ukr.net', 'zol.co.zw');
Mailcheck.defaultTopLevelDomains.push('com.au', 'com.br', 'ru', 'us')

function updateConditionals() {
  if (parent.$('#signupFormIframe3')) {
    parent.$('#signupFormIframe3').height($('body').height() + 20);
  }
}

function checkMandatory() {
  var ok2submit = 1;
  var errorFields = '';
  var atTest = /\@/;
  var dotTest = /\./;
  if ((atTest.test(document.signupForm.Email.value) == false) || (dotTest.test(document.signupForm.Email.value) == false)) {
    ok2submit = 0;
    errorFields += 'Email';
  }
  if (document.signupForm.User5.value == '') {
    ok2submit = 0;
    errorFields += ', Please select the closest city to where you live from the list';
  }
  if (document.signupForm.Lastname.value == '') {
    ok2submit = 0;
    errorFields += ', Lastname';
  }
  if (document.signupForm.Firstname.value == '') {
    ok2submit = 0;
    errorFields += ', Firstname';
  }
  if (document.signupForm.User8.value == '') {
    ok2submit = 0;
    errorFields += ', Would you like to attend the workshop and/or audition?';
  }
  if (ok2submit == 0) {
    var errorFields2 = errorFields.replace(/^\, /, '');
    alert('To submit this form, please ensure you have entered information for: ' + errorFields2);
    return false;
  } else {
    return true;
  }
}
$(document).ready(function() {
  $('#signup_Email').on('blur', function() {
    $('#emailEntryAlert').html('');
    $(this).mailcheck({
      suggested: function(element, suggestion) {
        $('#emailEntryAlert').html('Did you mean <a onclick="$(\'#signup_Email\').val(\'' + suggestion.full + '\'); $(\'#emailEntryAlert\').html(\'\');" style="text-decoration: underline; cursor: pointer;" title="Click here to make this your intended email address">' + suggestion.full + '</a>?');
      },
      empty: function(element) {
        if ($('#signup_Email').val() == '') {
          $('#emailEntryAlert').html('Be sure to enter a valid email address!');
        }
      }
    });
  });
  $(':input').on('click', function() {
    updateConditionals()
  });
  $(':input').on('blur', function() {
    updateConditionals()
  });
  $(':input').on('focus', function() {
    updateConditionals()
  });
  $(':input').on('keyup', function() {
    updateConditionals()
  });
  $('textarea').on('click', function() {
    updateConditionals()
  });
  $('textarea').on('blur', function() {
    updateConditionals()
  });
  $('textarea').on('focus', function() {
    updateConditionals()
  });
  $('textarea').on('keyup', function() {
    updateConditionals()
  });
  $('select').on('click', function() {
    updateConditionals()
  });
  $('select').on('blur', function() {
    updateConditionals()
  });
  $('select').on('focus', function() {
    updateConditionals()
  });
  $('select').on('change', function() {
    updateConditionals()
  });
  updateConditionals();
});

function get_action() {
  var optn_value = document.getElementById("signup_User5").value;
  var option_value = document.getElementById("signup_User8").value;
  if ((option_value == "Workshop Only") && (optn_value == "London")) {
    window.location = "http://www.mscurvaceousuk.com/mcuklondonworkshop.html";
  } else if ((option_value == "Workshop Only") && (optn_value == "Birmingham")) {
    window.location = "http://www.mscurvaceousuk.com/mcukbirminghamworkshop.html";
  } else if ((option_value == "Workshop Only") && (optn_value == "Manchester")) {
    window.location = "http://www.mscurvaceousuk.com/mcukmanchesterworkshop.html";
  } else if ((option_value == "Audition Only") && (optn_value == "London")) {
    window.location = "http://www.mscurvaceousuk.com/mcuk-london-audition-confirmation.html";
  } else if ((option_value == "Audition Only") && (optn_value == "Birmingham")) {
    window.location = "http://www.mscurvaceousuk.com/mcuk-birmingham-audition-confirmation.html";
  } else if ((option_value == "Audition Only") && (optn_value == "Manchester")) {
    document.signupForm.action = "http://www.mscurvaceousuk.com/mcuk-manchester-audition-confirmation.html";
  } else if ((option_value == "Audition + Workshop") && (optn_value == "London")) {
    window.location = "http://www.mscurvaceousuk.com/mcuk-london-audition-confirmation.html";
  } else if ((option_value == "Audition + Workshop") && (optn_value == "Birmingham")) {
    window.location = "http://www.mscurvaceousuk.com/mcuk-birmingham-audition-confirmation.html";
  } else if ((option_value == "Audition + Workshop") && (optn_value == "Manchester")) {
    window.location = "http://www.mscurvaceousuk.com/mcuk-manchester-audition-confirmation.html";
  }

}


function DoAllThese() {
  var retvalue;
  retvalue = checkMandatory();
  if (retvalue == false) {
    return retvalue;
  }
  retvalue = get_action();
}
body,
input,
select,
label,
li,
p,
div,
span {
  font-family: arial;
}
.formRow label {
  font-size: 16px;
}
#labelFullName {
  white-space: nowrap;
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
  <link rel="stylesheet" type="text/css" href="http://app.greenrope.com/styles/signup.css" />
  <link rel="stylesheet" type="text/css" href="http://app.greenrope.com/img/joinback/design10.css" />
  <script type="text/javascript" src="http://app.greenrope.com/app2/js/jquery/jquery-1.11.2.min.js">
  </script>
  <script type="text/javascript" src="http://app.greenrope.com/app2/js/jquery/jquery-migrate-1.2.1.min.js">
  </script>
  <script type="text/javascript" src="http://app.greenrope.com/scripts/signup.js">
  </script>
  <script type="text/javascript" src="http://app.greenrope.com/app2/js/mailcheck.min.js">
  </script>
  <title>Form
  </title>
  <link rel="Shortcut Icon" href="http://app.greenrope.com/users/myteam4/Media1884.ico" />
  <link rel="icon" href="http://app.greenrope.com/users/myteam4/Media1884.ico" type="image/x-icon" />
</head>

<body>
  <div id="container">
    <div id="logoDiv">
    </div>
    <div id="formTop">
    </div>
    <div id="formContainer">
      <form name="signupForm" id="signupForm" target="_top" method="post" action="http://app.greenrope.com/j1.pl?9ec6ce8b4e17b30b7c2a75edc1c1a684716721de718b418721aa61ed83378739" onsubmit="return DoAllThese();">
        <table>
          <tbody>
            <tr>
              <td>
                <ul id="teamFields">
                  <li class="formRow" id="field_Firstname">
                    <label class="fieldName" id="labelFirstname" for="signup_Firstname">First Name<span class="reqMarker">*</span>
                    </label>
                    <input type="text" name="Firstname" value="" maxlength="64" id="signup_Firstname" class="inputTextField" />
                  </li>
                  <li class="formRow" id="field_Lastname">
                    <label class="fieldName" id="labelLastname" for="signup_Lastname">Last Name<span class="reqMarker">*</span>
                    </label>
                    <input type="text" name="Lastname" value="" maxlength="64" id="signup_Lastname" class="inputTextField" />
                  </li>
                  <li class="formRow emailRow" id="field_Email">
                    <label class="fieldName" for="signup_Email">Email<span class="reqMarker">*</span>
                    </label>
                    <input type="text" name="Email" maxlength="64" value="" id="signup_Email" class="inputTextField" />
                    <div id="emailEntryAlert">
                    </div>
                  </li>
                  <li class="formRow userFieldName" id="field_User5">
                    <label class="fieldName" id="labelUser5" for="signup_User5">Please select the closest city to where you live from the list<span class="reqMarker">*</span>
                    </label>
                    <select name="User5" id="signup_User5">
                      <option value="">Choose</option>
                      <option value="London">London</option>
                      <option value="Birmingham">Birmingham</option>
                      <option value="Manchester">Manchester</option>
                    </select>
                  </li>
                  <li class="formRow userFieldName" id="field_User8">
                    <label class="fieldName" id="labelUser8" for="signup_User8">Would you like to attend the workshop and/or audition?<span class="reqMarker">*</span>
                    </label>
                    <select name="User8" id="signup_User8">
                      <option value="">Choose</option>
                      <option value="Workshop Only">Workshop Only</option>
                      <option value="Workshop + Audition">Workshop + Audition</option>
                      <option value="Audition Only">Audition Only</option>
                    </select>
                  </li>
                </ul>
                <ul id="teamSelection">
                  <li class="formRow joinRow"><span id="confirmText"> </span>
                  </li>
                  <input type="hidden" name="AutomaticTeamIDs" value="4" />
                  <input type="hidden" name="AutomaticTeamIDs" value="3" />
                  <input type="hidden" name="AutomaticTeamIDs" value="1" />
                </ul>
              </td>
            </tr>
          </tbody>
        </table>
        <div id="reqInfo">* required information
        </div>
        <input id="formSubmit" type="submit" name="formSubmit" style="font-weight: bold; font-size: 16px; color: #000000; border-style: solid; border-width: 8px !important; border-color: #d3d3d3 !important; border-radius: 0px !important; padding: 16px !important; background: #a9a9a9 !important; box-shadow: none !important;"
        value="Sign Me Up" />
        <input type="hidden" name="Referrer" value="" />
        <input type="hidden" name="qstring" value="9ec6ce8b4e17b30b7c2a75edc1c1a684716721de718b418721aa61ed83378739" />
        <input type="hidden" name="formSubmitCheck" value="1" />
      </form>
      <div id="formBottom">
      </div>
    </div>
  </div>
</body>

</html>

0 个答案:

没有答案