ボタンをクリックした後に最後に行を追加する動的テーブルを作成しました。1 つの列にdropdown list
、データベースの値を含めたいと考えています。
テーブルの作成方法は次のとおりです。
<script type="text/javascript">
function createRow() {
var row = document.createElement('tr'); // create row node
var col = document.createElement('td'); // create column node
var col2 = document.createElement('td'); // create secondcolumn node
var col3 = document.createElement('td'); // create next node
var col4 = document.createElement('td'); // create next column node
var col5 = document.createElement('td'); // create next column node
row.appendChild(col); // append first column to row
row.appendChild(col2); // append second column to row
row.appendChild(col3); // append next column to row
row.appendChild(col4); // append next column to row
row.appendChild(col5); // append next column to row
col.innerHTML = '<select name="search-alias-0017" id="hasla" title="Search in">' +
'<option value="aps" selected="selected">--Wybierz z listy--</option> ' +
'<option value="stripbooks">opcja</option>' +
'<option value="popular">Haslo2</option>' +
'</select>';
c//rest columns
var table = document.getElementById("tableToModify"); // find table to append to
table.appendChild(row); // append row to table
}
</script>
現在drop down list
、2つのオプションがあります。<option>
これを変更し、データベースからいくつかの変数をロードしました。これらの値をタグに入れたいと思います。実際に私のJS
外見:
<script type="text/javascript">
function createRow() {
<? $q = "select name from vulnerability";
$result = $db - > query($q) - > fetchall(); ?>
var options = '';
options += '<select name="search-alias-0017" id="hasla" title="Search in">';
for (var i = 0; i < <? echo $result(sizeof($result); ?> ; i++) {
options += '< option > <? echo $result[i]['name ']; ?> < /option>';
}
options+='</select > ';
var row = document.createElement('tr'); // create row node
var col = document.createElement('td'); // create column node
var col2 = document.createElement('td'); // create secondcolumn node
var col3 = document.createElement('td'); // create next node
var col4 = document.createElement('td'); // create next column node
var col5 = document.createElement('td'); // create next column node
row.appendChild(col); // append first column to row
row.appendChild(col2); // append second column to row
row.appendChild(col3); // append next column to row
row.appendChild(col4); // append next column to row
row.appendChild(col5); // append next column to row
col.innerHTML = options;
c//rest columns
var table = document.getElementById("tableToModify"); // find table to append to
table.appendChild(row); // append row to table
}
</script>
しかし、どういうわけか私のコードは機能しません...誰かが私が間違っていることのヒントを教えてくれますか?