2014-11-14 44 views
-1

感謝大家的幫助,這個項目實際上正在進行,我正在學習一些非常酷的技能,這要感謝大家的幫助。特別是Techstream和FormGet的人。使用TechNet中的一些代碼,我可以修改以適應我的工作人員使用的數據元素,以便他們可以添加文件夾名稱,然後爲每個文件夾名稱分配描述符,或者可以在提交併將它們插入之前從列表中刪除行數據庫。所以下一步就是設計一個函數,當他們按下submit時,一個php腳本會觸發並將數組插入到數據庫中。但是,當我將insertFunction()放入script.js時,它會導致其他兩個功能,允許用戶添加或刪除表單中的行以不起作用。有人可以看看這個,並告訴我我做錯了什麼嗎?我認爲可以在同一個script.js文件中有多個函數。這是我的代碼。明顯的函數addRow和函數deleteRow允許用戶添加或刪除用戶輸入表單中的行。而且他們的工作就像一個魅力,直到我將第三個函數insertFunction()添加到script.js。當添加insertFunction()時,似乎禁用addRowdeleteRow。似乎無法理解我做錯了什麼。感謝您的任何建議!添加到script.js的新功能導致其他兩個腳本無法工作

function addRow(tableID) {/*this function allows the user to add more rows to the form to a maximum of 10000*/ 
    var table = document.getElementById(tableID); 
    var rowCount = table.rows.length; 
    if(rowCount < 10000){       // limit the user from creating fields more than your limits 
     var row = table.insertRow(rowCount); 
     var colCount = table.rows[0].cells.length; 
     for(var i=0; i<colCount; i++) { 
      var newcell = row.insertCell(i); 
      newcell.innerHTML = table.rows[0].cells[i].innerHTML; 
     } 
    }else{ 
     alert("Contact Records Management if you have more than 10000 records."); 

    } 
} 

function deleteRow(tableID) { /*this function allows the user to delete rows from the form but requires they have at least 1 row*/ 
    var table = document.getElementById(tableID); 
    var rowCount = table.rows.length; 
    for(var i=0; i<rowCount; i++) { 
     var row = table.rows[i]; 
     var chkbox = row.cells[0].childNodes[0]; 
     if(null != chkbox && true == chkbox.checked) { 
      if(rowCount <= 1) {       // limit the user from removing all the fields 
       alert("You must have at least 1 folder."); 
       break; 
      } 
      table.deleteRow(i); 
      rowCount--; 
      i--; 
     } 
    } 
} 

function insertFunction() { /*This is the function that takes the user input from the form, validates and sends to filedetailinsert.php for insert into db*/ 

var officecode = document.getElementById("officecode").value; 
var myusername = document.getElementById("myusername").value; 
var day = document.getElementById("day").value; 
var month = document.getElementById("month").value; 
var year = document.getElementById("year").value; 
var creator = document.getElementById("creator").value; 
var officechief = document.getElementById("officechief").value; 
var status = document.getElementById("status").value; 
var BX_NAME = document.getElementById("BX_NAME").value; 
var BX_fileseries = document.getElementById("BX_fileseries").value; 
var BX_classification = document.getElementById("BX_classification").value; 
var BX_media = document.getElementById("BX_media").value; 

/*Returns successful data submission message when the entered data is inserted into database */ 

var dataString = 'officecode1=' +officecode+ 'myusername1=' +myusername+ 'day1=' +day+ 'month1=' +month+ 'year1=' +year+ 'creator1=' +creator+ 'officechief1=' +officechief+ 'status1=' +status+ 'BX_NAME1=' +BX_NAME+ 'BX_fileseries1=' +BX_fileseries 'BX_classification1=' +BX_classification+ 'BX_media1=' +BX_media; 

if 

(officecode == '' || myusername == '' || day == '' || month == '' || year == '' || creator == '' || officechief == '' || status == '' || BX_NAME == '' || BX_fileseries == '' || BX_classification == '' || BX_media == '') 

{ 
/*the statement above checks to see if all fields are populated. If there are empty fields it displays a message "Please Complete All Fields" and will not proceed to the $.ajax action below. When the user clicks ok on the error message they remain at the user input form to populate the field(s) they left blank. If all fields are populated then the $.ajax action fires, invoking filedetailinsert.php script to place the data into the database.*/ 


alert(Please Complete All Fields"); 


} 

else 

{ 
//AJAX code to submit form comes next 

$.ajax(

{ 
    type: "POST", 
url: "filedetailinsert.php", 
    data: dataString, 
    cache: false, 
    success: function(html) 

    { 
     alert(hmtl); 
    } 

} 

); 

} 


return false; 



} 
+2

了一句:'警報(請填寫所有字段 「);'缺少起始報價'」' – user887675 2014-11-14 15:05:36

+0

如上。由於SO語法高亮顯而易見。我**高度**推薦使用代碼編輯器來做同樣的事情。另外,在您的瀏覽器中使用JS控制檯,它會突出顯示錯誤 – Steve 2014-11-14 15:07:54

+0

但是,一個函數中的語法錯誤會導致前兩個函數停止工作? – Arioch9000 2014-11-14 15:13:15

回答

2
alert(Please Complete All Fields"); 

在郵件的開頭缺少一個雙引號。

應該是:

alert("Please Complete All Fields"); 
+0

正如我上面所問,一個函數中的語法錯誤會導致前兩個函數停止工作? – Arioch9000 2014-11-14 15:14:09

+0

是的,語法錯誤有這樣的效果。 – vaso123 2014-11-14 15:15:06

+0

好吧!我會糾正錯誤,看看會發生什麼!非常感謝大家的幫助! – Arioch9000 2014-11-14 15:17:03

相關問題