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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unable to get this working in both IE and FF

Status
Not open for further replies.

dg11

Programmer
Mar 4, 2007
3
GB
Hello,

New member,

I have a problem which can be seen here:

The search form on right side has two drop down fields

a)county which depending on choice here will then fill

b) town, this will work fine in I.E. but not in FF,

Can anyone help, thank you

:)
 
A couple of things just browsing through part of the source. Let's concentrated on select region only.

[1] The select-one element region.
><select class="formlogolaaddcounty" name="region" onChange="populateTown(document.globe,document.globe.region.options[document.globe.region.selectedIndex].value)" >

You could avoid hard code the form the select-one element is in, and also make it more concise but clearer.

[tt]<select class="formlogolaaddcounty" name="region" onChange="populateTown(this.form,this.value)" >[/tt]

[2] In the handler, there seems to have some problems, as I see it, in the construction. (Other might not help chastize your use of eval() as well.)
[tt]
function populateTown(inForm,selected) {
[red]//[/red]var selectedArray = eval(selected + "Array");
[blue]var selectedArray = window[selected + "Array");[/blue]
[red]//[/red]while (selectedArray.length < inForm.[blue]town.options.length) {
[red]//[/red]inForm.town.options[(inForm.options.town.length - 1)] = null;
[red]//[/red]}
[blue]inForm.town.length=[red]1[/red];[/blue] [green]//This will do, you are going to rebuid the whole town options in any case. But, the first component is kept.[/green]
[blue]//Add a conditional to make sure selectedArray exists, if needed, you have to make sure it is array too
if (selectedArray) {[/blue]
for (var i=[red]1[/red]; i < selectedArray.length; i++) {
[red]//[/red]eval("inForm.town.options=" + "new Option" + selectedArray); [green]//syntax is not correct by itself[/green]
[blue]inForm.town.options = new Option(selectedArray,selectedArray);[/blue]
}
[blue]} //added conditional on selectedArray[/blue]
if (inForm.region.options[0].value == '') {
inForm.region.options[0]= null;
if ( navigator.appName == 'Netscape') {
if (parseInt(navigator.appVersion) < 4) {
window.history.go(0);
}
else {
if (navigator.platform == 'Win32' || navigator.platform == 'Win16') {
window.history.go(0);
}
}
}
}
}
[/tt]
[2.1] In the above, you have script component [0] differently from other components. This may not be the most convenient choice. In any case, the rebuild keeps the first option component intact. (There may be some thing I don't see.)
[2.2] You may add a conditional to make sure eval() to a existing selectedArray otherwise, you may be trouble.

I think the other functions can be rewritten following the same ingredients shown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top