Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Java script function help

Status
Not open for further replies.

rbeech23

Programmer
Dec 22, 2002
14
GB
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, mail to robert.beech@ants.co.uk

Thanks

Html:
<script language=&quot;JavaScript1.1&quot; src=&quot;options-change.js&quot;></script>
<html>
<head>
<title>Meet on holiday - Welcome</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>

<!-- link to popups script -->
<script language=&quot;JavaScript&quot; src=&quot;scripts/popups.js&quot;>
// no text required here - activated from links on page
</script>

<script language=&quot;JavaScript&quot;>
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=&quot;JavaScript&quot;>
var subresortArray = new Array();subresortArray[0] = new Array ('Benidorm','Resort1');
subresortArray[1] = new Array ('Costa Dorada','Resort2');

</script>

<link rel=&quot;stylesheet&quot; href=&quot;styles.css&quot; type=&quot;text/css&quot;>
</head>

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

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

<form name=&quot;addholidayform&quot; method=&quot;post&quot;>
<tr>
<td><p align=&quot;center&quot;>
<select id=&quot;nnCountry&quot;
onChange=&quot;ChangeResortOptions('document.addholidayform.nnCountry',
'document.addholidayform.nnResort','resortArray');&quot;
name=&quot;nnCountry&quot;>
<option value=&quot;novalue&quot; selected>
Select a country...</option>
<option value='Andorra'>Andorra</option><option value='Australia'>Australia</option><option value='Austria'>Austria</option><option value='Bahamas'>Bahamas</option><option value='Balearic Islands'>Balearic Islands</option><option value='Belgium'>Belgium</option><option value='Bermuda'>Bermuda</option><option value='Brazil'>Brazil</option><option value='Bulgaria'>Bulgaria</option><option value='Canada'>Canada</option><option value='Canary Islands'>Canary Islands</option><option value='Channel Islands'>Channel Islands</option><option value='China'>China</option><option value='Costa Rica'>Costa Rica</option><option value='Croatia'>Croatia</option><option value='Cyprus'>Cyprus</option><option value='Czech Republic'>Czech Republic</option><option value='Denmark'>Denmark</option><option value='Egypt'>Egypt</option><option value='England'>England</option><option value='Estonia'>Estonia</option><option value='Finland'>Finland</option><option value='France'>France</option><option value='Germany'>Germany</option><option value='Gibraltar'>Gibraltar</option><option value='Greece'>Greece</option><option value='Hungary'>Hungary</option><option value='Iceland'>Iceland</option><option value='India'>India</option><option value='Ireland'>Ireland</option><option value='Israel'>Israel</option><option value='Italy'>Italy</option><option value='Jamaica'>Jamaica</option><option value='Japan'>Japan</option><option value='Kenya'>Kenya</option><option value='Korea'>Korea</option><option value='Latvia'>Latvia</option><option value='Lithuania'>Lithuania</option><option value='Malta'>Malta</option><option value='Mexico'>Mexico</option><option value='Morocco'>Morocco</option><option value='Netherlands'>Netherlands</option><option value='New Zealand'>New Zealand</option><option value='Nigeria'>Nigeria</option><option value='Norway'>Norway</option><option value='Poland'>Poland</option><option value='Portugal'>Portugal</option><option value='Puerta Rico'>Puerta Rico</option><option value='Romania'>Romania</option><option value='Russia'>Russia</option><option value='Scotland'>Scotland</option><option value='South Africa'>South Africa</option><option value='Spain'>Spain</option><option value='Sweden'>Sweden</option><option value='Switzerland'>Switzerland</option><option value='Thailand'>Thailand</option><option value='Tunisia'>Tunisia</option><option value='Turkey'>Turkey</option><option value='Venezuela'>Venezuela</option><option value='Wales'>Wales</option><option value='Yugoslavia'>Yugoslavia</option></select></p></td>
</tr>
<tr>
<td><p align=&quot;center&quot;>
<select id=&quot;nnResort&quot;
onChange=&quot;ChangeSubResortOptions('document.addholidayform.nnResort',
'document.addholidayform.SubResort','subresortArray');&quot;
name=&quot;nnResort&quot;>
<option value=&quot;novalue&quot; selected>
Select a resort...</option>
</select></p></td>
</tr>
<tr>
<td><p align=&quot;center&quot;>
<select name=&quot;SubResort&quot; id=&quot;SubResort&quot; style=&quot;visibility:hidden&quot;>
<option value=&quot;novalue&quot; selected>
Select a town/sub resort...</option>
</select></p></td>
</tr>
</form>
</table> </td>
<td background=&quot;images/searchbox-r.gif&quot;> </td>
</tr>
</table>
<p> </p>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
<td background=&quot;images/border-r.gif&quot; width=&quot;18&quot;> </td>
</tr>
</table>
<p align=&quot;center&quot;>
</div></body>
</html>


Javascript files (options-change.js)

function ChangeResortOptions(Country,Resort,CountryResort)
{

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

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

var listLen = 1;

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

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

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

}

function ChangeSubResortOptions(Resort,SubResort,ResortSubResort)
{

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

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

var listLen = 1;

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

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

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

}

function ChangeSubResortOptionsDS(Resort,SubResort,ResortSubResort)
{

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

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

var listLen = 1;

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

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

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

}

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


function r_trimmer(thisstring)
{
while(thisstring.charAt(thisstring.length-1)==&quot; &quot;)
{
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 + &quot;= 'visible'&quot;);
}

 
you need to post the popup.js file before I can figured out what is going on...
 
The popup.js file shouldn't actually be in there, it performs other functions elsewhere, if you remove the reference it doesn't affect the original problem I still have

Any other ideas appreciated
 
the code you sent doesn't seems to be populating the resort pull down menu. That's why I was asking about the popup.js...
 
The code populates the resort pull down menu via the function ChangeResortOptions. This works okay.
The reason for the thread is that I cant get the subresort pull down menu to work once resort has been selected. This should work via the function ChangeSubResortOptions which is almost a mirror of ChangeResortOptions.
Hope this helps.
Any further help appreciated
 
I understand what was your original request for help, but the code you sent is not populating the resort pull down menu...
Understand now...
 
Apologies for that, I've managed to figure it out now.

Thanks for your time
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top