2012-06-07 44 views
0

我有一個表單只是驗證用戶的年齡,然後提交它。該表單在FF中運行正常,Safari瀏覽器& Chrome,但不在IE 9上(我現在只在IE9上測試過)。表單按鈕不會在IE中提交

這裏是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提前 這裏是按鈕輸入

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

_The形式在FF,Safari瀏覽器和Chrome_工作正常 - 我不這麼認爲... – Andreas

+0

你的意思不是在IE瀏覽器中運行,則會給你和錯誤或者它沒有做任何事情? – shareef

+0

當我點擊提交按鈕時,它並沒有做任何事情,表格並不是要提交任何信息,而是一個年齡驗證代碼,在驗證您在您的法定飲酒年齡之後,您可以訪問該網站國家。 –

回答

0

使用它的一件事 「提交」 或函數調用。 如果您從按鈕單擊調用CalculateAge()函數,然後手動執行提交操作,則可以同時執行這兩個操作。像

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

嗨Rizstien,對不起,我沒有得到你。該表格只是驗證您是否屬於法定飲酒年齡,並且只是提交任何信息,而不允許您查看該網站。像重定向一樣。如果你可以包含一些示例代碼,我將不勝感激。 –

0

這裏的jsfiddle你與線

jsfiddle demo you code

if (d != \'0\' && m != \'0\' && y != \'0\') {修改刪除斜槓
alert(\'Input date is incorrect!\');修改刪除斜線

一些修改代碼

,因爲錯誤的這些行看到鏈接,看到修復,它的工作原理沒有修改任何東西

我已經測試了他們在Firefox和IE8

+0

thanx很多隊友,但我的問題是我沒有把一個下拉選擇的值,我在我的HTML選擇年齡。所以IE看到這些字段爲空。當我填充字段的值,它在IE和FF上工作得很好,thanx –

+0

thanx隊友,我應該在第一個地方發佈html,它會爲我們節省時間。但我很高興我解決了它:-) thanx再次 –

+0

什麼問題可以將我的答案接受爲幫助或什麼;) – shareef