开发者

Javascript event triggering error

Here am trying to display a drop down box of mysql table when the combo1 is clicked. am getting the following error in firebug.

combo1.attachEvent is not a function [Break On This Error] combo1.attachEvent("onchange", GetTables);

can anyone help me to make this code work ?

 function CreateForm_existing() {
doc.form1.stage.value = "import_setup";

// Empty workarea
EmptyWorkarea(div);

var workarea = doc.getElementById(div);

// Declare vars
var freeVar;
var i;
var a_href;

var table = _table.cloneNode(true);  // Create table
var tbody = _tbody.cloneNode(false);  // Create tbody

var row1 = _tr.cloneNode(false);    // Row for database
var cell11 = _td.cloneNode(false);  // Cell for words
var cell12 = _td.cloneNode(false);  // Cell for combo

var text1 = doc.createTextNode("Select database: ");
var combo1 = _select.cloneNode(false);  // SELECT control for database
    combo1.setAttribute("name", "dbName");
    combo1.attachEvent("onSelect", GetTables);
    combo1.options[combo1.length] = new Option("Select database", "");  // Add "Select database option"

for (i = 0; i < mysqlDatabaseArray.length; i++) {
    combo1.options[combo1.length] = new Option(mysqlDatabaseArray[i], mysqlDatabaseArray[i]);  // Add databases to options of SELECT control
}

row2 = _tr.cloneNode(false);    // Row for tables
cell21 = _td.cloneNode(false);  // Cell for word
cell22 = _td.cloneNode(false);  // Cell for combo

var text2 = doc.createTextNode("Select table: ");
var combo2 = _select.cloneNode(false);  // SELECT control for tables
    combo2.setAttribute("name", "dbTableName");


workarea.appendChild(table);
table.appendChild(tbody);

tbody.appendChild(row1);
    row1.appendChild(cell11);
        c开发者_如何学Cell11.appendChild(text1);
    row1.appendChild(cell12);
        cell12.appendChild(combo1);

tbody.appendChild(row2);
    row2.appendChild(cell21);
        cell21.appendChild(text2);
    row2.appendChild(cell22);
        cell22.appendChild(combo2);

combo1.focus();

}


You could try:

combo1.attachEvent("onchange", GetTables); 


The W3C way to do it is with: addEventListener(type,function,capture). attachEvent() is IE-specific.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜