Hi all,
For some reason my change() function is only called when the page loads. I'd
much rather it gets called when the select changes.
Here's the code:
window.onload = init;
function init() {
var new_select = new Selector('tdata ','myselect','m yid');
var new_select_list = new DataSource("som e_list");
new_select_list .addItem(1,"One ");
new_select_list .addItem(2,"Two ");
new_select_list .addItem(3,"Thr ee");
new_select_list .addItem(4,"Fou r");
new_select_list .addItem(5,"Fiv e");
new_select.setD ataSource(new_s elect_list);
new_select.form Input("form","i nput");
}
Selector = function(contai ner_id,name,id) {
var container = document.getEle mentById(contai ner_id);
this.node = document.create Element("select ");
//this.node = new Select();
container.appen dChild(this.nod e);
this.node.name = name;
this.node.id = id;
}
Selector.protot ype.setDataSour ce = function(ds) {
this.dataSource = ds;
for(var i = 0; i < ds.items.length ; i++) {
if(ds.items[i] != undefined) {
var option = new Option(ds.items[i],i,false,false) ;
this.node.optio ns[this.node.optio ns.length] = option;
}
}
}
Selector.protot ype.formInput = function(form,e lement) {
var myform = document.getEle mentById(form);
this.input = document.create Element("input" );
this.input.name = element;
//this.input.type = "hidden";
myform.insertBe fore(this.input ,myform.firstCh ild);
this.node.oncha nge = change(this);
}
function change(selector ) {
alert("hello");
selector.input. value = selector.node.v alue;
}
DataSource = function(name) {
this.name = name;
this.items = new Array();
}
DataSource.prot otype.addItem = function(id,ite m) {
this.items[id] = item;
}
and the html:
<html>
<head>
<script defer src="/javascript/selectors.js"
type="text/javascript"></script>
</head>
<body>
<form id=form>
<table border=1>
<tr>
<td>
Select:
</td>
<td id=tdata>
</td>
</tr>
</table>
</form>
</body>
</html>
For some reason my change() function is only called when the page loads. I'd
much rather it gets called when the select changes.
Here's the code:
window.onload = init;
function init() {
var new_select = new Selector('tdata ','myselect','m yid');
var new_select_list = new DataSource("som e_list");
new_select_list .addItem(1,"One ");
new_select_list .addItem(2,"Two ");
new_select_list .addItem(3,"Thr ee");
new_select_list .addItem(4,"Fou r");
new_select_list .addItem(5,"Fiv e");
new_select.setD ataSource(new_s elect_list);
new_select.form Input("form","i nput");
}
Selector = function(contai ner_id,name,id) {
var container = document.getEle mentById(contai ner_id);
this.node = document.create Element("select ");
//this.node = new Select();
container.appen dChild(this.nod e);
this.node.name = name;
this.node.id = id;
}
Selector.protot ype.setDataSour ce = function(ds) {
this.dataSource = ds;
for(var i = 0; i < ds.items.length ; i++) {
if(ds.items[i] != undefined) {
var option = new Option(ds.items[i],i,false,false) ;
this.node.optio ns[this.node.optio ns.length] = option;
}
}
}
Selector.protot ype.formInput = function(form,e lement) {
var myform = document.getEle mentById(form);
this.input = document.create Element("input" );
this.input.name = element;
//this.input.type = "hidden";
myform.insertBe fore(this.input ,myform.firstCh ild);
this.node.oncha nge = change(this);
}
function change(selector ) {
alert("hello");
selector.input. value = selector.node.v alue;
}
DataSource = function(name) {
this.name = name;
this.items = new Array();
}
DataSource.prot otype.addItem = function(id,ite m) {
this.items[id] = item;
}
and the html:
<html>
<head>
<script defer src="/javascript/selectors.js"
type="text/javascript"></script>
</head>
<body>
<form id=form>
<table border=1>
<tr>
<td>
Select:
</td>
<td id=tdata>
</td>
</tr>
</table>
</form>
</body>
</html>
Comment