S
Sky
Hi Guru,
I need some help with Array in Javascript in populating the list to
SELECT box dynamically
I have a form that contains:
- 3 HTML checkboxes for region (Europe, America, Asia)
- 1 HTML Select box for language that dynamically populated based
on the region selected (ListA)
Europe : English, French, German, Spanish, Italian
America: English, Spanish, Portuguese
Asia: English, Chinese, Japanese, Korean
Example:
If Europe and America Region are selected, then the Select box for
language will have following (with no repeat of same language):
English, French, German, Spanish, Italian, Portuguese
In my script, I declare:
var arr = new Array(); // temp arrary
var arr_EU = new
Array("English","French","German","Spanish","Italian");
var arr_AM = new Array("English","Spanish","Portuguese");
var arr_AS = new Array("English","Chinese","Japanese","Korean");
if (myform.Europe.checked==true)
{
// check current temp array, and compliment the temp array
with arr_EU
}
if (myform.Europe.checked==false)
{
// check current temp array, and remove the item that
(found exclusively in arr_EU, and not in other arr_AM/arr_AS, if
arr_AM/arr_AS was checked)
}
// do similar for "myform.America.checked" and
"myform.Asia.checked"
// clear existing items
myform.ListA.options.length = 0
// loops through the array adding item text/value
for(var i=0;i<arr.length;i++)
{
document.forms[0].ListA.options.length ++;
document.forms[0].ListA.options.value = arr.split(",")[0];
document.forms[0].ListA.options.text = arr.split(",")[1];
}
Please help. Many Thanks.
Regards,
Sky
I need some help with Array in Javascript in populating the list to
SELECT box dynamically
I have a form that contains:
- 3 HTML checkboxes for region (Europe, America, Asia)
- 1 HTML Select box for language that dynamically populated based
on the region selected (ListA)
Europe : English, French, German, Spanish, Italian
America: English, Spanish, Portuguese
Asia: English, Chinese, Japanese, Korean
Example:
If Europe and America Region are selected, then the Select box for
language will have following (with no repeat of same language):
English, French, German, Spanish, Italian, Portuguese
In my script, I declare:
var arr = new Array(); // temp arrary
var arr_EU = new
Array("English","French","German","Spanish","Italian");
var arr_AM = new Array("English","Spanish","Portuguese");
var arr_AS = new Array("English","Chinese","Japanese","Korean");
if (myform.Europe.checked==true)
{
// check current temp array, and compliment the temp array
with arr_EU
}
if (myform.Europe.checked==false)
{
// check current temp array, and remove the item that
(found exclusively in arr_EU, and not in other arr_AM/arr_AS, if
arr_AM/arr_AS was checked)
}
// do similar for "myform.America.checked" and
"myform.Asia.checked"
// clear existing items
myform.ListA.options.length = 0
// loops through the array adding item text/value
for(var i=0;i<arr.length;i++)
{
document.forms[0].ListA.options.length ++;
document.forms[0].ListA.options.value = arr.split(",")[0];
document.forms[0].ListA.options.text = arr.split(",")[1];
}
Please help. Many Thanks.
Regards,
Sky