N
nadia
I am have used php to create a two sets of arrays of listboxes, each
of the listbox in the array have a unique ID. One of the list boxes
are dependant on the other one. I have written the code in javascript,
well changed existing code. I need to be able to select the element by
ID rather than name. The code was working before I changed things to
"getElementByID". I am not very good at javascript so I am not sure if
I am on the right track, currently nothing is happening.
This is the Javascript code:
function swapName(form, i) {
var Type = 'lsType' + i;
var Name = 'lsName' + i;
Type = document.getElementByID(Type).options[document.getElementByID(Type).selectedIndex].value;
// this bit resets the name select list to nothing.
while (document.getElementByID(Name).options.length > 1)
document.getElementByID(Name).options[0] = null;
// this bit populates the name select list with the required cities.
if (Type.length > 0) {
current_array=Names[Type];
for (j=0;j<current_array.length;j++) {
var optionName = new Option(current_array[j], current_array[j],
false);
document.getElementByID(Name).options[document.getElementByID(Name).length]
= optionName;
}
}
}
This is the bit that calls it:
<select name="lsType[]" onChange="swapName(this.form,'.$i.')"
id="lsType'.$i.'">
Any suggestions would be welcome
Thanks in advance!
of the listbox in the array have a unique ID. One of the list boxes
are dependant on the other one. I have written the code in javascript,
well changed existing code. I need to be able to select the element by
ID rather than name. The code was working before I changed things to
"getElementByID". I am not very good at javascript so I am not sure if
I am on the right track, currently nothing is happening.
This is the Javascript code:
function swapName(form, i) {
var Type = 'lsType' + i;
var Name = 'lsName' + i;
Type = document.getElementByID(Type).options[document.getElementByID(Type).selectedIndex].value;
// this bit resets the name select list to nothing.
while (document.getElementByID(Name).options.length > 1)
document.getElementByID(Name).options[0] = null;
// this bit populates the name select list with the required cities.
if (Type.length > 0) {
current_array=Names[Type];
for (j=0;j<current_array.length;j++) {
var optionName = new Option(current_array[j], current_array[j],
false);
document.getElementByID(Name).options[document.getElementByID(Name).length]
= optionName;
}
}
}
This is the bit that calls it:
<select name="lsType[]" onChange="swapName(this.form,'.$i.')"
id="lsType'.$i.'">
Any suggestions would be welcome
Thanks in advance!