Javascript function help

wxdqz

New Member
Below is an html extract and a java script function.
The first box on the page allows you to select a country based on option values, once selected a javascript function runs which drills into an array and picks up all the resorts in that country. Fine.
When an option from the resorts box is selected a similar event should happen which picks up the sub resorts from another array based on resort selection. This is not happening. It doesn't seem to pass the resort value to the js function.

An example which should work is Spain, Benidorm.

Any help appreciated

Thanks

options-change.js
function ChangeResortOptions(Country,Resort,CountryResort)
{

var arrLen = eval(CountryResort + ".length");
var strKey1 = trim_string(eval(Country + ".options[" + Country + ".selectedIndex].value"));

eval(Resort + ".options.length = 0");
eval(Resort + ".options[0] = new Option('Select a resort...','?')");

var listLen = 1;

for (var i=0; i < arrLen; i++)
{
if (eval(CountryResort + "[0]") == trim_string(strKey1))
{
eval(Resort + ".options[listLen] = new Option(" + CountryResort + "[1])");
listLen = listLen + 1;
}
}

eval(Resort + ".options[0].selected = true");

if (document.layers)
{
history.go(0);
}

}

function ChangeSubResortOptions(Resort,SubResort,ResortSubResort)
{

var arrLen = eval(ResortSubResort + ".length");
var strKey1 = trim_string(eval(Resort + ".options[" + Resort + ".selectedIndex].value"));

eval(SubResort + ".options.length = 0");
eval(SubResort + ".options[0] = new Option('Select a town/sub resort...','?')");

var listLen = 1;

for (var i=0; i < arrLen; i++)
{
if (eval(ResortSubResort + "[0]") == trim_string(strKey1))
{
eval(SubResort + ".options[listLen] = new Option(" + ResortSubResort + "[1])");
listLen = listLen + 1;
}
}

eval(SubResort + ".options[0].selected = true");

if (document.layers)
{
history.go(0);
}
if (listLen > 1)
{
document.addholidayform.SubResort.style.visibility = 'visible';
}

}


function f_trimmer(thisstring)
{
while(thisstring.charAt(0)==" ")
{
thisstring=thisstring.substring(1,thisstring.length)
}
thisstring=r_trimmer(thisstring)
return thisstring
}


function r_trimmer(thisstring)
{
while(thisstring.charAt(thisstring.length-1)==" ")
{
thisstring=thisstring.substring(0,(thisstring.length-1))
}
return thisstring
}


function trim_string(thisstring)
{
return f_trimmer(thisstring)
}

function Unhide_Box(box_name)
{
eval(box_name + "= 'visible'");
}

html code:
<script language="JavaScript1.1" src=http://www.webdeveloper.com/forum/archive/index.php/"scripts/options-change.js"></script>
<html>
<head>
<title>Meet on holiday - Welcome</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script language="JavaScript">
var resortArray = new Array();resortArray[0] = new Array ('Andorra','Arinsal-Pal');
resortArray[1] = new Array ('Andorra','Pas de la Casa');
resortArray[2] = new Array ('Andorra','Soldeu El Tarter');
resortArray[3] = new Array ('Australia','Sydney');
resortArray[4] = new Array ('Austria','Kitzbuhel');
resortArray[5] = new Array ('Austria','Niederau');
resortArray[6] = new Array ('Austria','Saalbach');
resortArray[7] = new Array ('Austria','Salzburg');
resortArray[8] = new Array ('Austria','Soll');
resortArray[9] = new Array ('Austria','Vienna');
resortArray[10] = new Array ('Austria','Zell Am See');
resortArray[11] = new Array ('Bahamas','Nassau');
resortArray[12] = new Array ('Balearic Islands','Formentera');
resortArray[13] = new Array ('Balearic Islands','Ibiza');
resortArray[14] = new Array ('Balearic Islands','Majorca');
resortArray[15] = new Array ('Balearic Islands','Menorca');
resortArray[16] = new Array ('Belgium','Brussels');
resortArray[17] = new Array ('Bermuda','Hamilton');
resortArray[18] = new Array ('Brazil','Costa do Sauipe');
resortArray[19] = new Array ('Brazil','Rio de Janeiro');
resortArray[20] = new Array ('Bulgaria','Albena');
resortArray[21] = new Array ('Bulgaria','Golden Sands');
resortArray[22] = new Array ('Bulgaria','Nessebur');
resortArray[23] = new Array ('Bulgaria','St Konstantin');
resortArray[24] = new Array ('Spain','Benidorm');
resortArray[25] = new Array ('Spain','Costa Blanca');
resortArray[26] = new Array ('Spain','Costa Brava');
resortArray[27] = new Array ('Spain','Costa del Sol');
resortArray[28] = new Array ('Spain','Costa Dorada');
resortArray[29] = new Array ('Spain','Madeira');
resortArray[30] = new Array ('Spain','Madrid');
resortArray[31] = new Array ('Spain','Seville');

</script>

<script language="JavaScript">
var subresortArray = new Array();subresortArray[0] = new Array ('Benidorm','Resort1');
subresortArray[1] = new Array ('Costa Dorada','Resort2');

</script>

<link rel="stylesheet" href=http://www.webdeveloper.com/forum/archive/index.php/"styles.css" type="text/css">
</head>

<body bgcolor="#9966cc" text="#000000" leftmargin="0" topmargin="0" >
<div align="center">
<table width="730" border="0" cellspacing="0" cellpadding="0" align="center" height="500">
<tr>
<td width="20" height="20" background="images/border-tl.gif"> </td>
<td background="images/border-t.gif" height="20"> </td>
<td width="18" height="20" background="images/border-tr.gif"> </td>
</tr>
<tr>
<td background="images/border-l.gif" width="20"> </td>
<td bgcolor="#FFFFFF" valign="top">
<table width="680" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td colspan="3">
<table width="550" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td valign="top">
<p> </p>
<table width="350" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td background="images/searchbox-l.gif"> </td>

<td bgcolor="#ccccff" valign="middle"><table width="290" border="0" cellspacing="0"
cellpadding="0" align="center">

<form name="addholidayform" method="post">
<tr>
<td><p align="center">
<select id="nnCountry"
onChange="ChangeResortOptions('document.addholidayform.nnCountry',
'document.addholidayform.nnResort','resortArray');"
name="nnCountry">
<option value=http://www.webdeveloper.com/forum/archive/index.php/"novalue" selected>
Select a country...</option>
<option value='Andorra'>Andorra</option><option value='http://www.webdeveloper.com/forum/archive/index.php/Australia'>Australia</option><option value='http://www.webdeveloper.com/forum/archive/index.php/Austria'>Austria</option><option value='http://www.webdeveloper.com/forum/archive/index.php/England'>England</option><option value='http://www.webdeveloper.com/forum/archive/index.php/Spain'>Spain</option><option value='http://www.webdeveloper.com/forum/archive/index.php/Sweden'>Sweden</option><option value='http://www.webdeveloper.com/forum/archive/index.php/Yugoslavia'>Yugoslavia</option></select></p></td>
</tr>
<tr>
<td><p align="center">
<select id="nnResort"
onChange="ChangeSubResortOptions('document.addholidayform.nnResort',
'document.addholidayform.SubResort','subresortArray');"
name="nnResort">
<option value=http://www.webdeveloper.com/forum/archive/index.php/"novalue" selected>
Select a resort...</option>
</select></p></td>
</tr>
<tr>
<td><p align="center">
<select name="SubResort" id="SubResort" style="visibility:hidden">
<option value="novalue" selected>
Select a town/sub resort...</option>
</select></p></td>
</tr>
</form>
</table> </td>
<td background="images/searchbox-r.gif"> </td>
</tr>
</table>
<p> </p>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
<td background="images/border-r.gif" width="18"> </td>
</tr>
</table>
<p align="center">
</div></body>
</html>
 
Back
Top