ie select problem

K

kat

Hi,
I am a java newbie and and am wondering why this function that works
in Firefox by showing & hiding select lists, does not work in ie.

Here is my code, anysuggestions would be greatly appreciated.
function showRegion(state) {
statereg=state+'region';


//element1.style.display = 'none';
blankregion = document.getElementById('blankregion');

blankregion.style.display = 'none';

var elementArray=new Array();
var regionArray=new
Array("ACTregion","NSWregion","NTregion","QLDregion","SAregion","TASregion","VICregion","WAregion");
for(var i = 0; i < 8; ++i) {
elementArray = document.getElementById(regionArray);
if(statereg==regionArray){
//delete regionArray;
elementArray.style.display = 'block';

}else{
//hidden = document.getElementById(regionArray);
elementArray.style.display = 'none';
}
}

}
 
R

richard

Hi,
I am a java newbie and and am wondering why this function that works
in Firefox by showing & hiding select lists, does not work in ie.

Here is my code, anysuggestions would be greatly appreciated.

Repeat after me, "Javascript javascript javascript is not java!"

Where do we get catsup from? Cats?
 
R

Richard Cornford

Hi,
I am a java newbie and and am wondering why this function that works
in Firefox by showing & hiding select lists, does not work in ie.

Here is my code, anysuggestions would be greatly appreciated.
elementArray = document.getElementById(regionArray);
if(statereg==regionArray){
//delete regionArray;
elementArray.style.display = 'block';

}else{
//hidden = document.getElementById(regionArray);
elementArray.style.display = 'none';
}
}

}


Without any context (not even the associated mark-up) you are asking
for a wild guess. One of the problems with that is that if you are not
in a position to analyse the issue, and find the reason for yourself,
then you probably are not in a position to appreciate how many
possible guesses there are (and how few can be excluded by the minimal
information provided).

My first guess is that you are trying to refer to OPTION elements and
OPTION elements cannot be individually styled in IE, so the individual
setting of the style's display property is not working. Then the
values being applied to the - display - property may be problematic as
the default display property for an OPTION element appears to be
'inline' (by CSS 2 and 2.1 specs), which doesn't really make sense,
but sometimes W3C specs are like that.

Richard.
 
K

kat

Hi,
I am a java newbie and and am wondering why this function that works
in Firefox by showing & hiding select lists, does not work in ie.
Here is my code, anysuggestions would be greatly appreciated.
         elementArray = document.getElementById(regionArray);
         if(statereg==regionArray){
              //delete regionArray;
              elementArray.style.display = 'block';

         }else{
              //hidden = document.getElementById(regionArray);
              elementArray.style.display = 'none';
         }
     }


Without any context (not even the associated mark-up) you are asking
for a wild guess. One of the problems with that is that if you are not
in a position to analyse the issue, and find the reason for yourself,
then you probably are not in a position to appreciate how many
possible guesses there are (and how few can be excluded by the minimal
information provided).

My first guess is that you are trying to refer to OPTION elements and
OPTION elements cannot be individually styled in IE, so the individual
setting of the style's display property is not working. Then the
values being applied to the - display - property may be problematic as
the default display property for an OPTION element appears to be
'inline' (by CSS 2 and 2.1 specs), which doesn't really make sense,
but sometimes W3C specs are like that.

Richard.


Thanks Richard sorry I was posting this hastily, it refers to the
entire select element not an option.
I do appreciate how many options there are I have tried 4 different
methods to do this and none work in ie.
Basically if a user picks an option from one select list, then it
should display the corresponding secondary select list only.
Work in firefox a charm, but nothing happens in ie. The blank region
select is an empty list that display on load and the other secondary
lists are hidden.
 
R

RobG

Hi,
I am a java newbie and and am wondering why this function that works
in Firefox by showing & hiding select lists, does not work in ie.

Here is my code, anysuggestions would be greatly appreciated.
function showRegion(state) {
statereg=state+'region';

statereg is an undeclared variable and will become global. Keep it
local with var.

//element1.style.display = 'none';
blankregion = document.getElementById('blankregion');

Undeclared variable, see above.
blankregion.style.display = 'none';

var elementArray=new Array();

You can use an array literal here:

var elementArray = [];

but an array seems unnecessary (see below).

var regionArray=new
Array("ACTregion","NSWregion","NTregion","QLDregion","SAregion","TASregion","VICregion","WAregion");

You can use an array literal here:

var regionArray = ["ACTregion","NSWregion","NTregion","QLDregion",

"SAregion","TASregion","VICregion","WAregion"];

for(var i = 0; i < 8; ++i) {

Instead of hard coding the value 8, consider:

for (var i = 0, iLen = regionArray.length; i < iLen; ++i) {

so changing the length of the array by adding or removing regions
automatically changes the number of iterations (maybe you'll add
Norfolk Island, Antarctica, Macquarie Island or whatever later).

elementArray = document.getElementById(regionArray);


It seems to me that elementArray is not needed at all (see below)
if(statereg==regionArray){
//delete regionArray;
elementArray.style.display = 'block';


When showing an element, it is recommended to set its display property
to '' (empty string) so that it returns to whatever it has inherited,
been assigned by CSS or has as a default (which could be one of a
number of values).
}else{
//hidden = document.getElementById(regionArray);
elementArray.style.display = 'none';
}


Consider replacing the above with (wrapped for posting):

document.getElementById(regionArray).style.display =
(statereg == regionArray)? '' : 'none';


Anyhow, here is the function re-written and wrapped for posting,
tested in Firefox and IE:

function showRegion(state) {
var statereg = state + 'region';
var regionArray = ['ACTregion', 'NSWregion', 'NTregion',
'QLDregion', 'SAregion', 'TASregion', 'VICregion', 'WAregion'];

document.getElementById('blankregion').style.display = 'none';

for (var i = 0, iLen = regionArray.length; i < iLen; ++i) {
document.getElementById(regionArray).style.display =
(statereg == regionArray)? '' : 'none';
}
}

It's not particularly robust, you may want to add some testing of
input and return values depending on how confident you are of the
environment it will be operating in.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,002
Messages
2,570,260
Members
46,858
Latest member
FlorrieTuf

Latest Threads

Top