2013-04-08 212 views
0

我有一個名爲formApprove()的JavaScript函數,並在按鈕上的html onclick中調用該函數。出於某種原因,javascript函數未被識別,因爲firebug告訴我forApprove不是函數。下面是在頭代碼:Javascript函數無法識別onclick

<script type="text/javascript"> 
function formApprove() { 
var TheTextBox = document.getElementById("formApprove"); 
TheTextBox.value = 'true'; 
alert("hellp"); 
return true; 
} 
</script> 

下面是在身體的代碼:

<input type="submit" name="approve" value="Approve Membership" onclick="formApprove()" /> 

任何幫助,在此將不勝感激。

全碼:

<head> 
<script type="text/javascript"> 
function nextPrevious(txtElement, btnElement) { 
    switch(btnElement.name) { 
     case 'increase': 
      var numrows = document.getElementById("numOfRows"); 
      if (txtElement.value < Number(numrows.value)) { 
       txtElement.value++; 
      } else { 
        alert('You are alread at the end of the members'); 
        return false; 
      } 
      break; 
     case 'decrease': 

      if(txtElement.value > 1) { 
       txtElement.value--; 
      } else { 
        alert('You are alread at the begining of the members'); 
        return false; 
      } 
      break; 

     case 'goto': 
      alert(txtElement.value); 
      break; 
     default: 
    } 
    return true; 
} 

function approve() { 
    var TheTextBox = document.getElementById("formApprove"); 
    TheTextBox.value = 'true'; 
    alert("hellp"); 
    return true; 
} 

function formChange() { 
    var TheTextBox = document.getElementById("formSubmit"); 
    TheTextBox.value = 'true'; 
    return true; 
} 


function deleteRecord() { 
    var answer = confirm ("Are you sure you want to delete record?"); 
    if (answer) { 
     var TheTextBox = document.getElementById("formDelete"); 
     TheTextBox.value = 'true'; 
     return true; 
    } else {return false;} 

} 

</script> 
</head> 
<body> 
     <form name="members_view" method="POST" action="viewpending.php"> 
<br /> 
    <div id="buttons"> 
     <input type="submit" name="update" value="Update Record" onclick="formChange(this.form.elements['formSubmit'].value)" /> - 
     <input type="submit" name="decrease" value="Previous" onclick="nextPrevious(this.form.elements['record'], this)" /> - 
     <input type="submit" name="increase" value="Next" onclick="nextPrevious(this.form.elements['record'], this)" /> - 
     <input type="submit" name="delete" value="Delete Record" onclick="deleteRecord(this.form.elements['formSubmit'].value)" /> - 
     <input type="submit" name="approve" value="Approve Membership" onclick="approve()" /> 
    </div> 
</div> 
<div id="leftcase"> 
     <div class="label">First Name:</div><div class="input"><input size="40" type="text" name="FNAME" value="<?php echo $row['FNAME']; ?>" /></div> 
     <div class="label">Middle Name:</div><div class="input"><input size="40" type="text" name="MNAME" value="<?php echo $row['MNAME']; ?>" /></div> 
     <div class="label">Last Name:</div><div class="input"><input size="40" type="text" name="LNAME" value="<?php echo $row['LNAME']; ?>" /></div> 
     <div class="label">Full Name:</div><div class="input"><input size="40" type="text" name="FULL_NAME" value="<?php echo $row['FNAME'].' '.$row['MNAME'].' '.$row['LNAME']; ?>" /></div> 
     <div class="label">Nick Name:</div><div class="input"><input size="40" type="text" name="NNAME" value="<?php echo $row['NNAME']; ?>" /></div> 
     <div class="label">Spouse/Partner Name:</div><div class="input"><input size="40" type="text" name="H_COUNTRY" value="<?php echo $row['H_COUNTRY']; ?>" /></div> 
     <div class="label">Anniversary Date:</div><div class="input"><input size="40" type="text" name="B_ZIP" value="<?php echo $row['B_ZIP']; ?>" /></div> 
     <div class="label">Primary Email:</div><div class="input"><input size="40" type="text" name="EMAIL" value="<?php echo $row['EMAIL']; ?>" /></div> 
     <div class="label">Second Email:</div><div class="input"><input size="40" type="text" name="B_CITY" value="<?php echo $row['B_CITY']; ?>" /></div> 
     <div class="label">Home Street:</div><div class="input"><input size="40" type="text" name="H_STREET" value="<?php echo $row['H_STREET']; ?>" /></div> 
     <div class="label">Home City:</div><div class="input"><input size="40" type="text" name="H_CITY" value="<?php echo $row['H_CITY']; ?>" /></div> 
     <div class="label">Home State:</div><div class="input"><input size="40" type="text" name="H_STATE" value="<?php echo $row['H_STATE']; ?>" /></div> 
     <div class="label">Home Zip:</div><div class="input"><input size="40" type="text" name="H_ZIP" value="<?php echo $row['H_ZIP']; ?>" /></div> 
     <div class="label">Home Phone:</div><div class="input"><input size="40" type="text" name="H_PHONE" value="<?php echo $row['H_PHONE']; ?>" /></div> 
     <div class="label">Cell:</div><div class="input"><input size="40" type="text" name="H_CELL" value="<?php echo $row['H_CELL']; ?>" /></div> 
     <div class="label">Birth Date:</div><div class="input"><input size="40" type="text" name="H_WEB" value="<?php echo $row['H_WEB']; ?>" /></div> 
     <div class="label">Membership Exp:</div><div class="input"><input size="40" type="text" size="40" name="MEMBER_INFO" value="<?php echo $row['MEMBER_INFO']; ?>" /></div> 
     <div class="label">Retired Mil Info:</div><div class="input"><input size="40" type="text" name="B_STATE" value="<?php echo $row['B_STATE']; ?>" /></div> 
     <div class="label">1st tour from:</div><div class="input"><input size="40" type="text" name="B_COUNTRY" value="<?php echo $row['B_COUNTRY']; ?>" /></div> 
     <div class="label">1st tour Rank/Rate:</div><div class="input"><input size="40" type="text" name="B_WEB" value="<?php echo $row['B_WEB']; ?>" /></div> 
     <div class="label">1st tour cruise Book:</div><div class="input"><input size="40" type="text" name="B_PHONE" value="<?php echo $row['B_PHONE']; ?>" /></div> 
     <div class="label">2nd tour from:</div><div class="input"><input size="40" type="text" name="B_FAX" value="<?php echo $row['B_FAX']; ?>" /></div> 
     <div class="label">2nd tour Rank/Rate:</div><div class="input"><input size="40" type="text" name="PAGER" value="<?php echo $row['PAGER']; ?>" /></div> 
     <div class="label">2nd tour cruise Book:</div><div class="input"><input size="40" type="text" name="B_COMPANY" value="<?php echo $row['B_COMPANY']; ?>" /></div> 
     <div class="label">3rd tour from:</div><div class="input"><input size="40" type="text" name="B_TITLE" value="<?php echo $row['B_TITLE']; ?>" /></div> 
     <div class="label">3rd tour Rank/Rate:</div><div class="input"><input size="40" type="text" name="B_DEPT" value="<?php echo $row['B_DEPT']; ?>" /></div> 
     <div class="label">3rd tour cruise book:</div><div class="input"><input size="40" type="text" name="OFFICE_LOC" value="<?php echo $row['OFFICE_LOC']; ?>" /></div> 
</div> 
<div id="rightcase"> 
     <div class="label">Biography:</div><div class="input"><textarea rows="35" cols="80" name="NOTES" /><?php echo $row['NOTES']; ?></textarea></div> 

     <input type="hidden" id="record" name="record" value="<?php echo $_POST['record']; ?>"/>   
     <input type="hidden" id="formSubmit" name="formSubmit" value="<?php echo $_POST['formSubmit']; ?>" /> 
     <input type="hidden" id="formApprove" name="formApprove" value="<?php echo $_POST['formApprove']; ?>" /> 
     <input type="hidden" id="formDelete" name="formDelete" value="<?php echo $_POST['formDelete']; ?>" /> 
     <input type="hidden" id="numOfRows" name="numOfRows" value="<?php echo $num_rows; ?>" /> 
     <input type="hidden" id="ID" name="ID" value="<?php echo $_POST['ID']; ?>"/> 

</div> 
<div id="buttons"> 
     <input type="submit" name="update" value="Update Record" onclick="formChange(this.form.elements['formSubmit'].value)" > - <input type="submit" name="decrease" value="Previous" onclick="nextPrevious(this.form.elements['record'], this)" > - <input type="submit" name="increase" value="Next" onclick="nextPrevious(this.form.elements['record'], this)" > - <input type="submit" name="delete" value="Delete Record" onclick="deleteRecord(this.form.elements['formSubmit'].value)" > 
    </form> 
</body> 
+0

您的腳本標籤位於頭標籤之間嗎? – Adil 2013-04-08 17:43:42

+0

在此之前,螢火蟲會提及任何其他錯誤嗎?也許在頁面上出現某種語法錯誤。 – 2013-04-08 17:43:45

+2

@Rikonator這就是所需要的準確** ** **。這個函數需要聲明纔可以調用 – Ian 2013-04-08 17:44:22

回答

0

你可能有一個名稱衝突與功能和元素的名稱。

重新命名該函數或重命名文本框。

+0

我試圖改變功能名稱不起作用。 – 2013-04-08 19:30:48