Except for the obvious spaces in
Code:
option2.appendChild(document.createTextNode(js_arr ay[i]));
AND
document.getElementById('dropdown1').appendChild(s elect1);
Although i'm not sure what kind of data is in js_array. As long as it's only strings you should be fine.
Yeah, this script is called on change of a selectbox, reads the value of the selected item and then places the value in a single cell table:
<table><tbody><tr><td>value</td></tr></tbody></table>
Copy this code and save it in an empty html document.
Adjust it back to your original where appropriate.
Code:
<html>
<head>
<script type="text/javascript">
function displayDetails(){
if(document.getElementById("newtable")){
var oldNode = document.getElementById("newtable");
oldNode.parentNode.removeChild(oldNode);
}
var table = document.createElement("table");
table.id="newtable";
var tbody = document.createElement("tbody");
var tr = document.createElement("tr");
var td = document.createElement("td");
var idx = document.getElementById("trackid").selectedIndex;
var Svalue = document.getElementById("trackid").options[idx].value;
var Sdata = document.createTextNode(Svalue);
td.appendChild(Sdata);
tr.appendChild(td);
tbody.appendChild(tr);
table.appendChild(tbody);
document.getElementById('showtable').appendChild(table);
}
</script>
</head>
<body>
<div id="showtable"></div>
<form name="test" action="post">
<select name="selectbox" id="trackid" onchange="displayDetails();">
<option value="test1">test1
<option value="test2">test2
<option value="test3">test3
<option value="test4">test4
<option value="test5">test5
<option value="test6">test6
</select>
</form>
</body>
</html>
Last edited by Oneway; 08-14-2006 at 08:03 PM..
|