473,324 Members | 2,002 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Not working in Netscape: but it is in IE and firefox

Please help! This is the last coding hurdle before I am done with the
site I am presently working on. It seems like this should work, but it
isn't. (What is suppose to happen: when you select the option you want
from the drop down menu the appropriate <div> becomes visible). I have
put in some alerts to see where the code is failing, and for some
reason in Netscape it isn't completing the sequence. It seems like it
should be easy to fix... agh! Thank you.

<!--
function changeForm(what) {
for (var i=0; i<what.options.length; i++)
{
alert('number of options: ' + what.options.length)
if (what.options[i].selected) {
alert('selected ' + i)
if(document.all) {
alert('sees document.all')

document.all[what.options[i].value].style.visibility="visible";
} else if (document.layers){
alert('sees document.layers')
document.layers[what.options[i].value].visibility =
"visible";
} else {
alert('sees none')

document.all[what.options[i].value].style.visibility="visible";
}
} else {
alert('deselect ' + i)
if(document.all) {
alert('sees document.all')

document.all[what.options[i].value].style.visibility="hidden";
} else if (document.layers){
alert('sees document.layers')
document.layers[what.options[i].value].visibility =
"hidden";
} else {
alert('sees no')

document.all[what.options[i].value].style.visibility="hidden";
}
}
}
}

//-->
</script>

</head>

<FORM>
<SELECT NAME="selectList" onChange="changeForm(this.form.selectList)">
<OPTION VALUE="form1" SELECTED>Question 1
<OPTION VALUE="form2">Question 2
<OPTION VALUE="form3">Question 3
</SELECT>

<br>
<DIV STYLE="position: absolute">
</DIV>

<DIV ID="form1" style="position: absolute; visibility: visible;">
Answer 1
</DIV>

<DIV ID="form2" style="position: absolute; visibility: hidden;">
Answer 2
</DIV>

<DIV ID="form3" style="position: absolute; visibility: hidden;">
Answer 3 -
</DIV>

Jul 23 '05 #1
14 1472
On 11/07/2005 18:21, er***@telus.net wrote:

[snip]
It seems like this should work, but it isn't.
The all collection is a proprietary feature invented by Microsoft, and
implemented by few others. Mozilla recently decided to add 'silent'
support to cope with badly written code which doesn't check for support,
but blindly assumes the collection is available.

By 'silent', I mean that

if(document.all)

will fail in Firefox. Older versions of Mozilla software will fail
completely.

The solution is to use the getElementById method instead. The all
collection should be avoided for all but two conditions:

1) Providing getElementById emulation for browsers that don't
support it, but do implement the all collection. This only
really applies to IE4.
2) Providing a replacement for getElementsByTagName in IE5.x when
passing an asterisk (*) as an argument. These versions will
always return an empty collection, rather than all elements.

[snip]
<!--
Remove that and its closing delimiter, below.

if(!document.getElementById) {
document.getElementById = function() {
return null;
};
}

function changeForm(what) {
var f;

for(var i = 0, o = what.options, n = o.length; i < n; ++i) {
if(!(f = document.getElementById(o[i].value)) || !f.style) {
return;
}
f.style.display = o[i].selected
? ''
: 'none';
}
}

[snip]
<SELECT NAME="selectList" onChange="changeForm(this.form.selectList)">
Just:

<select name="selectList" onchange="changeForm(this);">

[snip]
<br>
<DIV STYLE="position: absolute">
</DIV>
Remove that,
<DIV ID="form1" style="position: absolute; visibility: visible;">


and use display property to control whether the element is rendered. You
can then remove the position declaration.

[snip]

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Jul 23 '05 #2
er***@telus.net wrote:
Please help! This is the last coding hurdle before I am done with the
site I am presently working on. It seems like this should work, but it
isn't. (What is suppose to happen: when you select the option you want
from the drop down menu the appropriate <div> becomes visible). I have
put in some alerts to see where the code is failing, and for some
reason in Netscape it isn't completing the sequence. It seems like it
should be easy to fix... agh! Thank you.
(not NN4, but it could be done):

function changeForm(what){
var x;
if((x=document.getElementById(what.options[what.selectedIndex].value)
&& x.style){
x.style.visibility=x.style.visibility=="hidden"?"v isible":"hidden";
}
}

<SELECT NAME="selectList" onChange="changeForm(this)">
Mick

<!--
function changeForm(what) {
for (var i=0; i<what.options.length; i++)
{
alert('number of options: ' + what.options.length)
if (what.options[i].selected) {
alert('selected ' + i)
if(document.all) {
alert('sees document.all')

document.all[what.options[i].value].style.visibility="visible";
} else if (document.layers){
alert('sees document.layers')
document.layers[what.options[i].value].visibility =
"visible";
} else {
alert('sees none')

document.all[what.options[i].value].style.visibility="visible";
}
} else {
alert('deselect ' + i)
if(document.all) {
alert('sees document.all')

document.all[what.options[i].value].style.visibility="hidden";
} else if (document.layers){
alert('sees document.layers')
document.layers[what.options[i].value].visibility =
"hidden";
} else {
alert('sees no')

document.all[what.options[i].value].style.visibility="hidden";
}
}
}
}

//-->
</script>

</head>

<FORM>
<SELECT NAME="selectList" onChange="changeForm(this.form.selectList)">
<OPTION VALUE="form1" SELECTED>Question 1
<OPTION VALUE="form2">Question 2
<OPTION VALUE="form3">Question 3
</SELECT>

<br>
<DIV STYLE="position: absolute">
</DIV>

<DIV ID="form1" style="position: absolute; visibility: visible;">
Answer 1
</DIV>

<DIV ID="form2" style="position: absolute; visibility: hidden;">
Answer 2
</DIV>

<DIV ID="form3" style="position: absolute; visibility: hidden;">
Answer 3 -
</DIV>

Jul 23 '05 #3
Mike:
Thanks for the clarification. For some reason I still cannot get it to
work. The script isn't changing the hidden to visible. If I set them
all to visible it works but when the page is first launched all
'questions' show up.

<script language="javascript">

if(!document.getElementById){
document.getElementById = function() {
return null;
};
}

function changeForm(what){
var f;

for(var i = 0, o = what.options, n = o.length; i < n; ++i)
{
if(!(f = document.getElementById(o[i].value)) || !f.style) {
return;
}
f.style.display = o[i].selected
? ''
: 'none';
}
}

</script>

</head>

<FORM>
<SELECT NAME="selectList" onchange="changeForm(this);">
<OPTION VALUE="form1" SELECTED>Select a question
<OPTION VALUE="form2">Question 2
<OPTION VALUE="form3">Question 3
</SELECT>

<DIV ID="form1" style="visibility: visible;">
Answer 1
</DIV>

<DIV ID="form2" style="visibility: hidden;">
Answer 2
</DIV>

<DIV ID="form3" style="visibility: hidden;">
Answer 3
</DIV>

Jul 23 '05 #4
On 11/07/2005 21:29, er***@telus.net wrote:

[snip]
For some reason I still cannot get it to work. The script isn't
changing the hidden to visible.
[snip]
f.style.display = o[i].selected
? ''
: 'none';
[snip]
<DIV ID="form1" style="visibility: visible;">


The script changes the display property, not visibility. This allows you
to hide the element so that it doesn't take up space without resorting
to absolutely positioning. In your current scheme, you'd use "display:
none;" to hide.

[snip]

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Jul 23 '05 #5
ASM
Mick White wrote:

(not NN4, but it could be done):
Ha! somebody thinking to NN4 ;-) thanks a lot.
(an chery on cake : small code understood by every navigator)

I run to try it (I didn't know NN4 could hide options)
function changeForm(what){
var x;
if((x=document.getElementById(what.options[what.selectedIndex].value)
&& x.style){
x.style.visibility=x.style.visibility=="hidden"?"v isible":"hidden";
}
}

<SELECT NAME="selectList" onChange="changeForm(this)">
Mick


Question :
when option is hidden, how to get it back visible ?
(I mean : how to choice the wanted option without seeing it)


<!--
function changeForm(what) {
for (var i=0; i<what.options.length; i++)
{
alert('number of options: ' + what.options.length)
if (what.options[i].selected) {
alert('selected ' + i)
if(document.all) {
alert('sees document.all')

document.all[what.options[i].value].style.visibility="visible";
} else if (document.layers){
alert('sees document.layers')
document.layers[what.options[i].value].visibility =
"visible";
} else {
alert('sees none')

document.all[what.options[i].value].style.visibility="visible";
}
} else {
alert('deselect ' + i)
if(document.all) {
alert('sees document.all')

document.all[what.options[i].value].style.visibility="hidden";
} else if (document.layers){
alert('sees document.layers')
document.layers[what.options[i].value].visibility =
"hidden";
} else {
alert('sees no')

document.all[what.options[i].value].style.visibility="hidden";
}
}
}
}

//-->
</script>

</head>

<FORM>
<SELECT NAME="selectList" onChange="changeForm(this.form.selectList)">
<OPTION VALUE="form1" SELECTED>Question 1
<OPTION VALUE="form2">Question 2
<OPTION VALUE="form3">Question 3
</SELECT>

<br>
<DIV STYLE="position: absolute">
</DIV>

<DIV ID="form1" style="position: absolute; visibility: visible;">
Answer 1
</DIV>

<DIV ID="form2" style="position: absolute; visibility: hidden;">
Answer 2
</DIV>

<DIV ID="form3" style="position: absolute; visibility: hidden;">
Answer 3 - </DIV>

--
Stephane Moriaux et son [moins] vieux Mac
Jul 23 '05 #6
ASM
er***@telus.net wrote:
Mike:
Thanks for the clarification. For some reason I still cannot get it to
work. The script isn't changing the hidden to visible.
no ... change the display (in Mike's function)
If I set them
all to visible it works but when the page is first launched all
'questions' show up.
<body onload="changeForm(document.forms[0].selectList);">

or better :

<style type="text/css">
#form1, #form2, #form3 { display: none; visisibility: visible }
</style>

If you use display and if your forms all are same hight
only the form displayed appears
on next choice the other form will take its place
<script language="javascript">

if(!document.getElementById){
document.getElementById = function() {
return null;
};
}

function changeForm(what){
var f;

for(var i = 0, o = what.options, n = o.length; i < n; ++i)
{
if(!(f = document.getElementById(o[i].value)) || !f.style) {
return;
}
f.style.display = o[i].selected
? ''
: 'none';
}
}

</script>

</head>

<FORM>
<SELECT NAME="selectList" onchange="changeForm(this);">
<OPTION VALUE="form1" SELECTED>Select a question
<OPTION VALUE="form2">Question 2
<OPTION VALUE="form3">Question 3
</SELECT>
<DIV ID="form1"> Answer 1
</DIV>
<DIV ID="form2"> Answer 2
</DIV>
<DIV ID="form3"> Answer 3
</DIV>

--
Stephane Moriaux et son [moins] vieux Mac
Jul 23 '05 #7
Mick,
I am also trying to get your code to work... can you tell me what I am
doing wrong? (I am getting javascript errors)

<script language="javascript">

function changeForm(what) {
var x;
if((x=document.getElementById(what.options[what.selectedIndex].value)
&& x.style)
{
x.style.visibility=x.style.visibility=="hidden"?"v isible":"hidden";
}
}
</script>

</head>

<FORM>
<SELECT NAME="selectList" onChange="changeForm(this)">
<OPTION VALUE="form1" SELECTED>Question 1
<OPTION VALUE="form2">Question 2
<OPTION VALUE="form3">Question 3
</SELECT>
<br>

<DIV ID="form1" style="visibility: visible;">
Answer 1
</DIV>

<DIV ID="form2" style="visibility: hidden;">
Answer 2
</DIV>

<DIV ID="form3" style="visibility: hidden;">
Answer 3
</DIV>

Jul 23 '05 #8
er***@telus.net wrote:
Mick,
I am also trying to get your code to work... can you tell me what I am
doing wrong? (I am getting javascript errors)

Sorry, a typo:
if((x=document.getElementById(what.options[what.selectedIndex].value))
&& x.style)

Note the added ")"

Mick

[snip]
Jul 23 '05 #9
ASM
er***@telus.net wrote:
Mick,
I am also trying to get your code to work... can you tell me what I am
doing wrong? (I am getting javascript errors)

<script language="javascript">

function changeForm(what) {
var x;
if((x=document.getElementById(what.options[what.selectedIndex].value)&& x.style)


if(x=document.getElementById(what.options[what.selectedIndex].value)&&
x.style)

but does no more work with me
I do that (less clean) :

<script type="text/javascript">
<!--
function changeForm(what){
for(var i=0;i<what.length;i++)
if(document.getElementById&&document.getElementByI d(what.options[i].value))
document.getElementById(what.options[i].value).style.display='none';
var x = what.options[what.selectedIndex].value;
if(x=document.getElementById(x))
x.style.display='block';
else alert('Sorry, such a question doesn\'t exist');
}
//-->
</script>
<style type="text/css">
#form1, #form2, #form3 { display: none }
</style>
<form>
<SELECT onChange="changeForm(this)">
<OPTION VALUE="form1" SELECTED>Question 1
<OPTION VALUE="form2">Question 2
<OPTION VALUE="form3">Question 3
<OPTION VALUE="form4">Question 4
</SELECT>
</form>
<form id="form1">
<input type=submit value=" F O R M _ 1 ">
</form>
<form id="form2">
<input type=submit value=" F O R M _ 2 ">
</form>
<form id="form3">
<input type=submit value=" F O R M _ 3 ">
</form>
</html>
--
Stephane Moriaux et son [moins] vieux Mac
Jul 23 '05 #10
ASM
Mick White wrote:

Sorry, a typo:
if((x=document.getElementById(what.options[what.selectedIndex].value))
&& x.style)

Note the added ")"


Ho yes ! but why ?

doing that (thought both equal)
if(x=document.getElementById(what.options[what.selectedIndex].value)&&x.style)
gives an error

--
Stephane Moriaux et son [moins] vieux Mac
Jul 23 '05 #11
On 13/07/2005 23:22, ASM wrote:

[snip]
if(x=document.getElementById(what.options[what.selectedIndex].value)&&x.style)

gives an error


The assignment operator has a very low precedence, so what you're
executing above is effectively the same as:

var t = document.getElementById(...),
x = t && x.style;

if(x) ...

instead of:

var x = document.getElementById(...);

if(x && x.style) ...

At the moment x.style is evaluated in the first case, x is still
undefined so attempting to access a property results in an error.

You must force the assignment to occur first, which is why Mick
introduced parentheses around that particular part of the expression.

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Jul 23 '05 #12
ASM wrote:
er***@telus.net wrote:
Mick,
I am also trying to get your code to work... can you tell me what I am
doing wrong? (I am getting javascript errors)

<script language="javascript">

function changeForm(what) {
var x;
if((x=document.getElementById(what.options[what.selectedIndex].value)&&
x.style)

if(x=document.getElementById(what.options[what.selectedIndex].value)&&
x.style)

but does no more work with me


Or for me....
var x;
if(
(x=document.getElementById(what.options[what.selectedIndex].value)
&&
x.style)

Works for me, note the parentheses: "(" and ")".
Mick

[snip]

Jul 23 '05 #13
Mick White wrote:
[...]
if((x=document.getElementById(what.options[what.selectedIndex].value)&&
x.style)
if(x=document.getElementById(what.options[what.selectedIndex].value)&&
x.style)

but does no more work with me


Or for me....
var x;
if(
(x=document.getElementById(what.options[what.selectedIndex].value)

) /* <--- ????? */ &&
x.style)

Works for me, note the parentheses: "(" and ")".
Mick


uhm... Mick? you didn't just by chance add the "missing-parentheses-typo" again?

if((x=document.getElementById(what.options[what.selectedIndex].value))&&x.style)
12 3 32 1
.. ^
Jul 23 '05 #14
Robi wrote:
[snip]

uhm... Mick? you didn't just by chance add the "missing-parentheses-typo" again?

if((x=document.getElementById(what.options[what.selectedIndex].value))&&x.style)
12 3 32

if
(
(
x=document.getElementById
(
what.options[what.selectedIndex].value
)
)
&& x.style
)

Mick
Jul 23 '05 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Peregrine Maitland | last post by:
I have scrolling news that is based on JavaScript on the site I maintain. The script works in Internet Explorer 6.x, but not Firefox 1.0. It's not clear to me why the script doesn't work with...
6
by: christian9997 | last post by:
Hi I would be very helpful if someone could help me with this code. It works fine in IE but when I display it in Netscape or Firefox and I move the mouse from one menu to the other the gap...
1
by: RC | last post by:
I know DTD (Document Type Definition) is supported by Netscape/Firefox and IE. But I typed some examples from http://www.w3schools.com/schema/default.asp Seems no effect on those browsers.
3
by: Arne | last post by:
I have a dropdownlist/select box with an autopostback to code behind. It works great in Internet Explorer, but doesn't work in Netscape and Firefox. What kind of support does ASP.net promise for...
1
by: Jordan | last post by:
I set the cursor property to change to the "hand" when the user performs an "onmouseover" event on a hyperlink object. This does work correctly with Internet Explorer, however, with Netscape and...
6
by: Mark Olbert | last post by:
The doPostBack javascript functioning is not submitting the page when called by linkbuttons (or an autopostback checkbox, for that matter). I'm aware of a problem with Netscape browsers and the...
10
by: News | last post by:
I have a page up trying to learn how to ID a browser and other info. http://wyght.com/warren/testPos.html here is the code <script type = "text/javascript"> var space = ", "; var name...
49
by: Atul Chaturvedi | last post by:
If we use ASP.NET 2.0 Login Control, we are unable to click on Login and Reset Buttons on Safari running on Apple Mac OS X Version 10.3.2 . How can i resolve the problem.
1
by: dscriv | last post by:
Hello, I have Netscape 8.0.4 (in Firefox mode) and Flash 8.0.24.0. I also have IE and Firefox installed. If I go to this page, which contains a Flash detection movie:...
7
by: Joe | last post by:
I've been playing around with atlas for hte past couple days and its very impressive. However the standard browser here is Netscape, specifically: Netscape 7.02 Mozilla/5.0 (Windows; U; Windows NT...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.