我有一個我正在生成的表,它有一個排序按鈕。我想獲得用戶想要進行排序的列,但我不斷收到在不大不小的未定義的值,當我嘗試從「通過柱」獲得的價值: 一些幫助,將不勝感激:表單提交給定未定義的值
function createTable(data){
var str = "<form id='tableSelect' action='javascript:void(0);'><table><thead><tr> <th>TicketNum</th><th>Recieved</th><th>SenderName</th><th>Sender Email</th><th>Subject</th><th>Tech</th><th>Status</th><th>Select</th></tr></thead><tbody>";
for(var key in data){
if (!data.hasOwnProperty(key)) continue;
var row = data[key];
str += "<tr> <td>";
str += row['TicketNum'] + "</td><td>";
str += row['Recieved'] + "</td><td>";
str += row['SenderName'] + "</td><td>";
str += row['SenderEmail'] + "</td><td>";
str += row['Subject'] + "</td><td>";
str += row['Tech'] + "</td><td>";
str += row['Status'] + "</td><td>";
str += "<input type='radio' name ='selectRow' value=" +row['TicketNum'] + ">" + "</td></tr>";
}
str += "<tr><td> Sort By: <input type = 'radio' name = 'byColumn' value='TicketNum'><td> Sort By: <input type = 'radio' name = 'byColumn' value='Recieved'><td> Sort By: <input type = 'radio' name = 'byColumn' value='SenderName'><td> Sort By: <input type = 'radio' name = 'byColumn' value='SenderEmail'><td> Sort By: <input type = 'radio' name = 'byColumn' value='Subject'><td> Sort By: <input type = 'radio' name = 'byColumn' value='Tech'><td> Sort By: <input type = 'radio' name = 'byColumn' value='Status'><td> <button type ='button' value='Submit' button class=\"myButton\" onclick=\"sort();\">Sort</button> </tr>";
str += "</tbody></table></form>";
console.log(str);
document.getElementById("table").innerHTML = str;
}
function sort(){
var table = currentTable;
var sortby = document. getElementsByName("byColumn").value; //the error is on this line
alert(sortby);
}
如果你的問題是關於'NULL'值,那麼這是一個SQL問題。如果您重新提出問題並添加查詢,可能會很有用。 – Eugene
我的意思是我提交表單時得到的空值...所以在排序函數的第二行 –
更新:使用'getElementsByName(「byColumn」)'並循環遍歷所有檢查巫婆檢查以獲取值 看到這個https://jsfiddle.net/MamdouhFreelancer/yrub1mac/1/ –