I can't seem to figure out how to assign an event handler to the select I created

I've tried everything I can think of, can anyone help me?

I'd really appreciate it.

--James



<form name="theform" method="post">
<input type="text" id="echothing2">
</form>

<script>
//this fills the fields array with the fieldnames from my database

<?php
dbconnect("Asset_Database");
$keys=tablekeys("Assets");
echo "fields = new Array(";
for ($i=0;$i<count($keys);$i++) {
echo "\"".$keys[$i]."\" ";
if ($i<(count($keys)-1)) {echo ",";}
}
echo ")";
?>


//this is the function to let me know that my even handler worked
function echothing() {
document.theform.echothing2.value="Changed!";}



//this create a select and populates it with the options from
//the fields array (the fields in my database)
selectnode=document.createElement("SELECT","fieldselect1");
document.theform.appendChild(selectnode);

//This is the part that's not working.
//I want to set an event handler for the select I created.
selectnode.setAttribute("onchange","echothing()");

for (var i=0;i<fields.length;i++) {
var theoption = document.createElement("OPTION");
selectnode.options.add(theoption);
theoption.innerText = fields[i];
theoption.value = fields[i];
}