2014-02-18 19 views
0

現在你說之前有一個答案在這裏,我嘗試了幾個,沒有制定出來,比如這個: Trigger a button click with JavaScript on the Enter key in a text box如何獲得進入關鍵在JavaScript提交表單

現在我有這個小密碼保護網站只能通過輸入密碼頁面訪問,現在如果我點擊提交時,密碼錯誤的消息框將出現,但如果我點擊輸入頁面重新加載一個稍微不同的地址。即使密碼正確,頁面仍然不會重新加載。

這裏是網站: http://bodokh.co.nf/

HTML:

<table border="1" cellspacing="0" cellpadding="0" bgcolor="#FFFFBD"> 
    <tr> 
    <td width="100%"><form name="password1"><div align="center"><center><p><strong>Enter password: </strong><input 
     type="text" name="password2" size="15"><br> 
     <input type="button" value="Submit" onClick="submitentry();"></p> 
     </center></div> 
    </form> 
    </td> 
    </tr> 
</table> 

JS:

function max(which) { 
    return (pass[Math.ceil(which) + (3 & 15)].substring(0, 1)) 
} 

function testit(input) { 
    temp = numletter.indexOf(input) 
    var temp2 = temp^parseInt(pass[phase1 - 1 + (1 | 3)].substring(0, 2)) 
    temp2 = numletter.substring(temp2, temp2 + 1) 
    return (temp2) 
} 


function submitentry() { 
    t3 = '' 
    verification = document.password1.password2.value 
    phase1 = Math.ceil(Math.random()) - 6 + (2 << 2) 
    var indicate = true 
    for (i = (1 & 2); i < window.max(Math.LOG10E); i++) 
     t3 += testit(verification.charAt(i)) 
    for (i = (1 & 2); i < lim; i++) { 
     if (t3.charAt(i) != pass[phase1 + Math.round(Math.sin(Math.PI/2) - 1)].charAt(i)) 
      indicate = false 
    } 
    if (verification.length != window.max(Math.LOG10E)) 
     indicate = false 
    if (indicate) 
     window.location = verification + extension 
    else 
     alert("Invalid password. Please try again") 
} 
+0

請發表你的代碼在這裏,這樣一旦你修復你的網站,這個問題就會保持有效。 – Barmar

+0

儘量讓問題變得簡單。它更簡潔,你可能最終只能回答你自己的問題/ – Lowkase

+0

你應該使用'return false'來不提交表單使用php或任何服務器端語言 –

回答

0

如果你想有一個一致的和可靠的方式對提交表單,你應該使用運行submitentry

<form onsubmit="submitentry();"> 
    ... 
</form> 

代替

<input ... onClick="submitentry();"> 
+0

當我這樣做時,按鈕的工作和輸入都沒有。 – Bodokh

+0

現在很奇怪。你究竟做了什麼? – marionebl

0

而不是調用從提交按鈕的onclick處理程序,從形式的onsubmit處理程序調用它submitentry()的:

<table border="1" cellspacing="0" cellpadding="0" bgcolor="#FFFFBD"> 
    <tr> 
    <td width="100%"><form name="password1" onsubmit="return submitentry();"><div align="center"><center><p><strong>Enter password: </strong><input 
     type="text" name="password2" size="15"><br> 
     <input type="button" value="Submit"></p> 
     </center></div> 
    </form> 
    </td> 
    </tr> 
</table> 

和提交函數應該返回false,以防止正常表單提交:

function submitentry() { 
    t3 = ''; 
    verification = document.password1.password2.value; 
    phase1 = Math.ceil(Math.random()) - 6 + (2 << 2); 
    var indicate = true; 
    for (i = (1 & 2); i < window.max(Math.LOG10E); i++) { 
     t3 += testit(verification.charAt(i)); 
    } 
    for (i = (1 & 2); i < lim; i++) { 
     if (t3.charAt(i) != pass[phase1 + Math.round(Math.sin(Math.PI/2) - 1)].charAt(i)) { 
      indicate = false; 
     } 
    } 
    if (verification.length != window.max(Math.LOG10E)) { 
     indicate = false; 
    } 
    if (indicate) { 
     window.location = verification + extension 
    } else { 
     alert("Invalid password. Please try again"); 
    } 
    return false; 
} 
+0

謝謝,但由於某種原因,無論我嘗試做什麼,只是不會讓我提交輸入按鈕。不過謝謝你的時間。 – Bodokh

相關問題