2012-06-06 55 views
-2

即時通訊工具完全新,我做了一個項目,我們得到@大學這種形式,但js似乎根本沒有工作。我沒有得到任何錯誤,它只是沒有工作!我有我的Javascript啓用,我完全禁用沒有腳本。javascript doesnt運行

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <link rel="stylesheet" type="text/css" href="<?php echo $_SESSION['css'];?>"/> 


<script type="text/javascript"> 


    function validate_f() { 
    var result=true; 
    var username=document.getElemenetById('username').value; 
    var illegalChars = /\W/; 
    var x=document.getElemenetById('email').value; 
     var pwd=document.getElemenetById('password').value; 


    if (illegalChars.test(username) || username.length>25) { 
     result=false; 

     alert("Username must be latin chars and not more than 25 characters"); 
    } 

if (x==null || x=="" || username == null || username=="" || pwd == null || pwd == "" || afm == null || afm == "") { 
result=false; 
alert("you have to fill up all the Boxes dude"); 
} 
    return result; 

} 
<div id="main"> 
<div id="formcontainer"> 
<form id="data" name="data" action="connection.php" method="POST" on submit="return validate_f()"> 
<table width="100%" cellpadding="3" cellspacing="2"> 
<tr> 
    <td width="25%"> </td> 
</tr> 
<tr> 
    <td class="right" width="20%"> <strong> Username </strong> </td> 
    <td> 
    <input type="text" name="username" id="username" size="25" maxlength="25"/> 
</td> 
</tr> 
<tr> 
    <td class="right"> <strong> Password</strong> </td> 
    <td> 
    <input type="password" name="password" id="password" size="25" maxlength="25"/> 
</td> 
</tr> 
<tr> 
    <td class="right"> <strong> Email</strong> </td> 
    <td> 
    <input type="text" name="email" id="email"/> 
    </td> 
</tr> 
<?php 
/* 
<tr> 
<td class="right"> <strong> Security Code: </strong> </td> 
<td> 
<img src="CaptchaSecurityImages.php" alt="" /> 
<input id="security_code" name="security_code" type="text" /> 
</td> 
</tr> 
*/ 
?> 
<tr> 
<td> 
      <input name="reset" type="reset" id="reset" value="Reset" /> 
      <input name="submit" type="submit" id="submit" value="Submit"/> 

     </td> 
</tr> 
</table> 
</form> 
</div> 

</div> 
+0

存在空白是補間「開」和「提交」。去掉它。 – Bergi

+2

你把'div's放在'head'裏面了嗎?沒有'body',你也沒有關閉'html'或'head'標籤?或者這是一個「部分」混合代碼? –

+0

在&提交之間有空格。試試這行表單標籤...

Talha

回答

2

有onsubmit事件

<form id="data" name="data" action="connection.php" method="POST" onsubmit="return validate_f()"> 
1

之間沒有空格之間存在上&提交空間。試試這個線形態標記......

<form id="data" name="data" action="connection.php" method="POST" onsubmit="return validate_f()"> 

  1. div's<form>標籤內。
  2. 關閉</script>標記,在<form>開始之前。
  3. 在開始<form>標記之前關閉</head>標記。
  4. 關閉html頁面末尾的</html>標籤。
0

試試這個,

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <link rel="stylesheet" type="text/css" href="<?php echo $_SESSION['css'];?>"/> 


<script type="text/javascript"> 


    function validate_f() { 
     var result = true; 
     var username = document.getElemenetById('username').value; 
     var illegalChars = /\W/; 
     var x = document.getElemenetById('email').value; 
     var pwd = document.getElemenetById('password').value; 



     if (illegalChars.test(username) || username.length > 25) { 
      result = false; 

      alert("Username must be latin chars and not more than 25 characters"); 
     } 

     if (x == null || x == "" || username == null || username == "" || pwd == null || pwd == "" || afm == null || afm == "") { 
      result = false; 
      alert("you have to fill up all the Boxes dude"); 
     } 
     return result; 

    } 
</script> 
</head> 


<body><div id="main"> 
<div id="formcontainer"> 
<form id="data" name="data" action="connection.php" method="POST" on submit="return validate_f()"> 
<table width="100%" cellpadding="3" cellspacing="2"> 
<tr> 
    <td width="25%"> </td> 
</tr> 
<tr> 
    <td class="right" width="20%"> <strong> Username </strong> </td> 
    <td> 
    <input type="text" name="username" id="username" size="25" maxlength="25"/> 
</td> 
</tr> 
<tr> 
    <td class="right"> <strong> Password</strong> </td> 
    <td> 
    <input type="password" name="password" id="password" size="25" maxlength="25"/> 
</td> 
</tr> 
<tr> 
    <td class="right"> <strong> Email</strong> </td> 
    <td> 
    <input type="text" name="email" id="email"/> 
    </td> 
</tr> 
<?php 

<tr> 
<td class="right"> <strong> Security Code: </strong> </td> 
<td> 
<img src="CaptchaSecurityImages.php" alt="" /> 
<input id="security_code" name="security_code" type="text" /> 
</td> 
</tr> 


<tr>  
<td> 
      <input name="reset" type="reset" id="reset" value="Reset" /> 
      <input name="submit" type="submit" id="submit" value="Submit"/> 

     </td> 
</tr> 
</table> 
</form> 
</div> 

</div> 
</body> 

</html>