HI FOLKS,
I have created a layer in a file called selectlist.js and have the
following code there
this.setHTML('<form NAME="main" ACTION="somewhere.asp" METHOD="GET">'+
'<input TYPE="HIDDEN" NAME="Avail">'+
'<input TYPE="HIDDEN" NAME="Sel">'+
'<table width ="100%" height="100%" BORDER=1 CELLPADDING=0
CELLSPACING=0>'+
'<tr>'+
'<td VALIGN="TOP" STYLE="width: 50px;"
WIDTH=50>Available Items:<br>'+
'<select MULTIPLE NAME="AvailItems" size=7>'+
'<option VALUE="1">Item 1 should not exceed the
width</option>'+
'<option VALUE="2">Item 2</option>'+
'</select>'+
'</td>'+
'<td ALIGN="CENTER"> <input TYPE="BUTTON" NAME="AddBtn"
VALUE=">>" OnClick="parent.addItems(this.form.AvailItems,
this.form.SelItems); parent.removeItems(this.form.AvailItems);"> <br>'+
'<br> <input TYPE="BUTTON" NAME="RemoveBtn"
VALUE=" << "
OnClick="parent.addItems(this.form.SelItems, this.form.AvailItems);
removeItems(this.form.SelItems);"> <br>'+'</td>'+'<td
VALIGN="TOP">Selected Items:<br>'+
'<select MULTIPLE NAME="SelItems" SIZE="5">'+
'</select>'+
'</td>'+
'</tr>'+
'</table>'+
'</form>',false);
now, where the button is initialized, I have on click methods that are
prototype to the Selectlist.
these are as follows
SelectList.prototype.addItems = function(fromCtrl, toCtrl) {
var i;
var j;
var itemexists;
var nextitem;
// step through all items in fromCtrl
for (i = 0; i < fromCtrl.options.length; i++) {
if (fromCtrl.options[i].selected) {
// search toCtrl to see if duplicate
j = 0;
itemexists = false;
while ((j < toCtrl.options.length) && (!(itemexists))) {
if (toCtrl.options[j].value == fromCtrl.options[i].value) {
itemexists = true;
alert(fromCtrl.options[i].value + " found!");
}
j++;
}
if (!(itemexists)) {
// add the item
nextitem = toCtrl.options.length;
toCtrl.options[nextitem] = new
Option(fromCtrl.options[i].text);
toCtrl.options[nextitem].value = fromCtrl.options[i].value;
}
}
}
}
SelectList.prototype.removeItems = function(fromCtrl) {
var i = 0;
var j;
var k = 0;
while (i < (fromCtrl.options.length - k)) {
if (fromCtrl.options[i].selected) {
// remove the item
for (j = i; j < (fromCtrl.options.length - 1); j++) {
fromCtrl.options[j].text = fromCtrl.options[j+1].text;
fromCtrl.options[j].value = fromCtrl.options[j+1].value;
fromCtrl.options[j].selected =
fromCtrl.options[j+1].selected;
}
k++;
} else {
i++;
}
}
for (i = 0; i < k; i++) {
fromCtrl.options[fromCtrl.options.length - 1] = null;
}
}P
My Problem is that when I change the OnClick function of the buttons
OnClick="parent.addItems(this.form.SelItems, this.form.AvailItems);
removeItems(this.form.SelItems); to
OnClick="top.listpanel.addItems(this.form.SelItems,
this.form.AvailItems); removeItems(this.form.SelItems);
where in the HTML document the widget has been initalized like
listpanel = new SelectList(myParameters, myParameters, myParameters,
myParameters, myParameters, );
it seems to be working
How do I refer to the methods of the Layer without having to use the
name "listpanel" in this case in order to refer to it.
how can I refer to these methods within the HTML
any help would be appreciated
|