简体   繁体   English

表单按钮不会在IE中提交

[英]Form Button Won't submit in IE

I have a form that just verifies the age of a user then submits it. 我有一个仅验证用户年龄然后提交的表格。 The form works fine in FF, Safari & Chrome but not on IE 9 (i have only tested it on IE9 for now). 该表格可以在FF,Safari和Chrome中正常运行,但不能在IE 9上运行(我目前仅在IE9上进行过测试)。

Here is the javascript 这是JavaScript

 <script type="text/ecmascript">
         function CalculateAge() {

        var a= document.getElementById("c").value;
         var d=document.getElementById("d").value;
         var m=document.getElementById("m").value;
         var y=document.getElementById("y").value;



         if (d != \'0\' && m != \'0\' && y != \'0\' ) {

            now = new Date()



            if (d) {

               /* born = new Date(y, d, m);

                age = Math.floor((now.getTime() - born.getTime()) / (365.25 * 24 * 60 * 60 * 1000)); */
                //from php spence

            /* now.getDate();//daty of month 1-30
            now.getFullYear();//four digits
            now.getMonth();//return month from 0-11
            */
            year_diff =now.getFullYear() - y;
            month_diff= (now.getMonth()+1)-m;
            day_diff=now.getDate()-d;

            if(month_diff<0){ 

            //--year_diff;
            y=year_diff-1;

            }

            else if((month_diff==0) && (day_diff<0)){ 


            //--year_diff;
            y=year_diff-1;

            }else{
            y=year_diff;
            }
            //alert(y);
            //alert(day_diff);
                //alert(year_diff);
                //alert(month_diff);
            //age=year_diff;
            b=a;
            h=new Number(b)+1;
            //alert("You are "+y+" years old and Your Country is "+document.getElementById("c").options[h].text);
            age=y;
            //alert(age);
                if(isNaN(age))

                {

                   alert(\'Input date is incorrect!\');

                }else if(a=="none"){
                alert("please select a country");
                }

                else

                {


                if(a==1||a==2||a==3||a==4||a==5||a==6||a==7||a==8||a==9||a==11||a==14||a==15||a==16||a==17||a==18||a==19||a==20||a==21||a==22||a==23||a==24||a==25||a==27||a==28||a==29||a==30||a==31||a==33||a==34||a==35||a==36||a==37||a==38||a==39||a==40||a==41||a==42||a==43||a==44||a==45||a==46||a==47||a==48||a==49||a==50||a==51||a==52||a==53||a==55||a==56||a==57||a==58||a==60||a==61||a==63||a==64||a==65||a==66||a==67||a==68||a==69||a==70||a==71||a==72||a==73||a==74||a==76||a==83||a==84||a==85||a==89||a==90||a==91||a==93||a==96||a==97||a==98||a==99||a==100||a==102||a==103||a==104||a==105||a==106||a==107||a==108||a==109||a==110||a==111||a==112||a==113||a==114||a==115||a==116||a==117||a==118||a==119||a==120||a==121||a==122||a==123||a==124||a==125||a==127||a==128||a==129||a==130||a==131||a==136||a==137||a==139||a==140||a==141||a==142||a==143||a==144||a==145||a==146||a==147||a==148||a==149||a==151||a==152||a==154||a==155||a==156||a==157||a==158||a==159||a==160||a==162||a==163||a==164||a==167||a==168||a==170||a==171||a==172||a==174||a==175||a==176||a==177||a==178||a==179||a==180||a==182||a==183||a==184||a==186||a==188||a==190||a==191||a==192||a==193||a==195||a==196||a==197){

if(age>=18){
    document.cookie ="chdg=testcookie; expires=3600; path=/tpfnew";
    window.location="index.php";

}
else{

window.location="reject.html";
}


}else if(a==32||a==92){

if(age>=19){
document.cookie ="chdg=testcookie; expires=3600; path=/tpfnew";
window.location="index.php";

}
else{

window.location="reject.html";
}

}
else if(a==86||a==138){
if(age>=20){
document.cookie = "chdg=hjko; expires=3600; path=/tpfnew";
window.location="index.php";

}
else{

window.location="reject.html";
}


}else if(a==187||a==185||a==161||a==150||a==135||a==133||a==79||a==75||a==12){
if(age>=21){
document.cookie ="chdg=testcookie; expires=3600; path=/tpfnew";
window.location="index.php";

}
else{

window.location="reject.html";
}
}

else if(a==78){
if(age>=25){
document.cookie ="chdg=testcookie; expires=3600; path=/tpfnew"; 
window.location="index.php";

}
else{

window.location="reject.html";
}

}
else if (a){window.location="reject2.html";}





        // window.location="welcome.php";
                    //alert(x+"is the "+age);
                    //alert(age);




            }}

        }else{alert("please select your Date of Birth.")}

    }




    </script>

thanx in advance And here is the button input 预先谢谢,这是按钮输入

<input type="button" onclick="CalculateAge();" value="Submit" />

use it for one thing "submit" or function call. 将其用于“提交”或函数调用。 You can do both if you call CalculateAge() function from button click and then perform submit action in that manually. 如果您通过单击按钮调用CalculateAge()函数,然后在其中手动执行提交操作,则可以同时进行。 Like 喜欢

function CalculateAge(){
  //DO your Stuff here
  jQuery.post(<your URL> , jQuery('#formid).serialize(),function(data){
      jQuery('#your result div').html(data);
  });
}

here is jsfiddle for you code with some modification in lines 这是jsfiddle为您提供代码,并在行中进行了一些修改

jsfiddle demo you code jsfiddle演示您的代码

the line if (d != \\'0\\' && m != \\'0\\' && y != \\'0\\' ) { modified removed slashes 该行if (d != \\'0\\' && m != \\'0\\' && y != \\'0\\' ) {修改后的斜杠
the line alert(\\'Input date is incorrect!\\'); alert(\\'Input date is incorrect!\\'); modified removed slashes 修改后的斜杠

because errors on these line see the link to see fix and it works without modifying any thing else 因为这些行上的错误都可以看到链接以查看修复,并且该链接无需修改就可以正常工作

i have tested them on firefox and ie8 我已经在firefox和ie8上对其进行了测试

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM