2012-07-16 56 views
0

我不太確定添加按鈕是否對這個問題負責,因爲它完全在其他瀏覽器上工作。無論如何,我希望你能幫助我。謝謝。順便說一下,這裏是完整的.php代碼。(PHP&JavaScript)href添加按鈕在Mozilla上不起作用,但適用於IE和Google

<html> 

<head> 

<LINK REL=StyleSheet HREF="addOfficerStyle.css" TYPE="text/css" MEDIA=screen> 

<script type="text/javascript"> 
    function validateForm(action) 
     { 
      var lname=document.forms["validation"] ["lname"].value; 
      var fname=document.forms["validation"] ["fname"].value; 
      var mname=document.forms["validation"] ["mname"].value; 
      var address=document.forms["validation"] ["address"].value; 
      var contact=document.forms["validation"] ["contact"].value; 

       if (lname==null || lname=="" || fname==null || fname=="" || mname==null || mname=="" || address==null || address=="" || contact==null || contact=="") 
        { 
        alert("Fill all required fields"); 
        return false; 
        } 
       else{ 
        form = document.getElementById('userLocation'); 
        form.action = action; 
        form.submit(); 
        } 
     } 


    function numeric(e) 
     { 
      var unicode=e.charCode ? e.charCode : e.keyCode; 
       if (unicode==8 || unicode==9 || (unicode >=48 && unicode <=57)) 
        { 
        return true; 
        } 
       else 
        { 
        return false; 
        } 
     } 

    function inputLimiter(e,allow) 
     { 
      var AllowableCharacters = ''; 

       if (allow == 'Letters'){AllowableCharacters=' ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';} 

      var k = document.all?parseInt(e.keyCode): parseInt(e.which); 
       if (k!=13 && k!=8 && k!=0) 
        { 
         if ((e.ctrlKey==false) && (e.altKey==false)) 
          { 
           return (AllowableCharacters.indexOf(String.fromCharCode(k))!=-1); 
          } 
         else 
          { 
           return true; 
          } 
        } 
       else 
        { 
         return true; 
        } 
     } 
</script> 

</head> 

<body onunload="opener.location=('PromoOfficer.php')"> 

<br><br> 

<form id="userLocation" name="validation" method="post" onsubmit="return validateForm()"> 
    <div id="tableAlign"> 
    <table> 
     <tr> 
      <td><b>ADD: Promo Officer</td></b> 
     </tr> 
     <tr> 
       <td>Last name:</td> <td><input type="text" name="lname" maxlength="20" onkeypress="return inputLimiter(event,'Letters')" /></td> 
     </tr>     
     <tr> 
       <td>First name:</td> <td><input type="text" name="fname" maxlength="20" onkeypress="return inputLimiter(event,'Letters')" /></td> 
     </tr>  
     <tr>  
       <td>Middle name:</td> <td><input type="text" name="mname" maxlength="20" onkeypress="return inputLimiter(event,'Letters')" /></td> 
     </tr> 
     <tr> 
       <td>Address:</td>  <td><input type="text" name="address" maxlength="50" /></td> 
     </tr> 
     <tr> 
       <td>Contact:</td>  <td><input type="text" name="contact" maxlength="11" onkeypress="return numeric(event);" /></td> 
     </tr> 
     <tr> 
       <td>User Type:</td> <td><input type name = "usertype" readonly = "true" value = "Promo Officer"></td> 
     </tr> 
    </table> 
    </div> 
<div id="addBtn"> 
     <a href="#" onclick="javascript: validateForm(action);return false;"><img src="images/add.png" height="27" width="60"></a> 
</div>  
<!-- PHP --> 
<? 
    include('global.php'); 


    if(isset($_REQUEST['salesID'])) 
     $pID = $_REQUEST['salesID']; 
    else 
     $pID = ""; 

    if(isset($_REQUEST['lname'])) 
     $lname = $_REQUEST['lname']; 
    else 
     $lname = ""; 

    if(isset($_REQUEST['fname'])) 
     $fname = $_REQUEST['fname']; 

    if(isset($_REQUEST['mname'])) 
     $mname = $_REQUEST['mname']; 

    if(isset($_REQUEST['address'])) 
     $address = $_REQUEST['address']; 

    if(isset($_REQUEST['contact'])) 
     $contact = $_REQUEST['contact']; 

    if(isset($_REQUEST['usertype'])) 
     $usertype = $_REQUEST['usertype']; 

      if($_POST) 
       { 

        $query = "INSERT INTO promoofficerform SET "; 
        $query = $query."LastName='".$lname."', "; 
        $query = $query."FirstName='".$fname."', "; 
        $query = $query."MiddleName='".$mname."', "; 
        $query = $query."Address='".$address."', "; 
        $query = $query."Contact='".$contact."', "; 
        $query = $query."UserType='".$usertype."' "; 
        //$query = $query."WHERE PromoNameID='".$pID."'"; 
        //echo $query; 
        ExecuteQuery($query); 
        echo "<script type=\"text/javascript\"> 
         <!-- 
         window.close(); 
         //--> 
         </script>"; 
       } 
?> 

<!-- EndOfPHP --> 

</form> 

</body> 

</html> 
+0

上面的代碼被運輸到jsfiddle ...看到它在這裏:http://jsfiddle.net/mDnpq/ – 2012-07-16 08:44:32

+0

當在FF中運行時,JS錯誤說「opener爲空」,在onload甚至在你的身體標記。點擊提交按鈕時的另一個JS錯誤是「action is not defined」...在這裏你的表單中使用了'function validateForm(action)' – 2012-07-16 08:53:47

回答

0

東西不對這個代碼:

<a href="#" onclick="javascript: validateForm(action);return false;"> 

應該寫成:

<a href="#" onclick="validateForm(document.forms['userLocation'].action);return false;"> 

指向您的驗證窗體的動作。

+0

非常感謝你的幫助!它的工作原理:對不起,如果我回答遲到。再次,謝謝你這麼多:) – jamie 2012-07-18 03:12:19

+0

@JamieBayot你忘了接受答案,只需點擊複選標記接受這個答案。 – 2012-07-18 03:37:53

0

你可能不會把javascript:onclick屬性。包含on前綴的屬性是回調(有效的JS函數)。 javascript:就像協議規範。因此,您只能在href屬性中使用javascript:。喜歡的東西:

<a href="javascript: alert(123)">test</a> 

解決您的問題只是從onlick刪除javascript:

<div id="addBtn"> 
     <a href="#" onclick="validateForm(action);return false;"><img src="images/add.png" height="27" width="60"></a> 
</div> 
+0

非常感謝你的幫助。我欠你們大好時光:) – jamie 2012-07-18 03:14:21

相關問題