My JS is limited so be gentle. I want to use a menu/list to alter the content of a page. I was able to retrieve and output the content from DB but I don’t know how to output it in the proper place on the page. I tried using id to identify a table and then getElementById to post the information there, but I don’t think I’m using it correctly, or perhaps there is a better approach all together.
Most of this is done through PHP so disregard any extra garbage (‘ or ;;;, etc.). I tried to delete out the unrelated code.
JS script: (I removed all the PHP db content retrieval, because that is working ok)
[CODE]<script type=”text/javascript” language=”javascript”>
function getphdlist(form) {
//…phpjunk
var phdarray = new Array();
//…phpjunk
phdarray[‘ . $j . ‘] = new Array(//…phpjunk
);
var startyr = 1996;
var curyr = 2005;
var range = curyr – startyr;
var x = 0;
var z = form.phdyear.value;
while (x < range – 1) {
document.getElementById(phd).write(“<tr><td>”+phdarray[z][x][0]+”</td><td>”+phdarray[z][x][1]+”</td></tr>”);
x++;
}
}</script>
Menu:
[CODE]<form name=”phdyrsel” id=”phdyrsel” onChange=”getphdlist(this)”>
<select name=”phdyear” class=”bodytext” id=”phdyear”>
<option class=”bodytext” value=”all” selected>(All)</option>’;
…
echo ‘<option class=”bodytext” value=”‘ . $i . ‘”>’ . $per . ‘</option>’;
…
}
</select>
</form>’;
Table:
[CODE]<tr>
<td colspan=”2″><table id=”phd” name=”phd”></table></td></tr>
The error I recieve: document.getElementById(phd).write is not a function. Looking through some of the other posts on this (getElementById) it looks like this method is used for altering attributes (ie document.getElementById.style = …). Is there a way to use this as a reference to a place on the page? I also tried adding document.getElementById to the function call (in the form) but it still didn’t work right. How can I get this content to post in the right place?
I’m still learning JS so feel free to suggest alternate methods other than getElementById.
Thanks in advance. ?