使用表单操作更改器对特定域名进行电子邮件验证

时间:2017-02-26 19:39:40

标签: javascript php html

<form name="form" method="post" action="">
    <input name="email" type="email" id="email" placeholder="email@school.com" required>
    <input name="name" type="text" id="name" placeholder="name" required>
    <button type="submit" id="submit">Submit!</button>
</form>

 <script>
    function IsValidEmail(email)
    $(document).ready(function() {
        $("#form").submit(function() {
        var allowedDomains = [ 'school1.com', 'school2.com', 'school3.com' ];
        if ($.inArray(str[0], allowedDomains) !== -1) {
             //acceptable
        }else{
             //not acceptable
        }


    document.getElementById('email').onchange = function(){
    document.getElementById('FORM_ID').action = '/'+this.value;
}
</script>
请帮助我 谢谢

2 个答案:

答案 0 :(得分:1)

请检查此代码,

<table>

这是您的javascript代码

z-index

你想用javascript回答所以这是javascipt回答

答案 1 :(得分:0)

第一个问题是您没有表单ID,因此您的document.getElementByID无法定位。我们先给它一个id emailform

<form id="emailform" name="form" method="post" action="">

然后您需要对更改运行有效性检查:

document.getElementById('email').onchange = function() {
  var allowedDomains = ['school1.com', 'school2.com', 'school3.com'];
  if ($.inArray(this.value, allowedDomains) !== -1) {
    //acceptable
  }
}   

然后您只需使用jQuery更新表单,设置action属性:

document.getElementById('email').onchange = function() {
  var allowedDomains = ['school1.com', 'school2.com', 'school3.com'];
  if ($.inArray(this.value, allowedDomains) !== -1) {
    var action = '/'+this.value;
    $("#emailform").attr("action", action);
  }
} 

希望这有帮助! :)