473,804 Members | 3,705 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.le ngth)
if (what.options[i].selected) {
alert('selected ' + i)
if(document.all ) {
alert('sees document.all')

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

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

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

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

//-->
</script>

</head>

<FORM>
<SELECT NAME="selectLis t" onChange="chang eForm(this.form .selectList)">
<OPTION VALUE="form1" SELECTED>Questi on 1
<OPTION VALUE="form2">Q uestion 2
<OPTION VALUE="form3">Q uestion 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 1505
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 getElementsByTa gName 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.ge tElementById) {
document.getEle mentById = function() {
return null;
};
}

function changeForm(what ) {
var f;

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

[snip]
<SELECT NAME="selectLis t" onChange="chang eForm(this.form .selectList)">
Just:

<select name="selectLis t" onchange="chang eForm(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.selectedIn dex].value)
&& x.style){
x.style.visibil ity=x.style.vis ibility=="hidde n"?"visible":"h idden";
}
}

<SELECT NAME="selectLis t" onChange="chang eForm(this)">
Mick

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

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

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

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

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

//-->
</script>

</head>

<FORM>
<SELECT NAME="selectLis t" onChange="chang eForm(this.form .selectList)">
<OPTION VALUE="form1" SELECTED>Questi on 1
<OPTION VALUE="form2">Q uestion 2
<OPTION VALUE="form3">Q uestion 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="javas cript">

if(!document.ge tElementById){
document.getEle mentById = function() {
return null;
};
}

function changeForm(what ){
var f;

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

</script>

</head>

<FORM>
<SELECT NAME="selectLis t" onchange="chang eForm(this);">
<OPTION VALUE="form1" SELECTED>Select a question
<OPTION VALUE="form2">Q uestion 2
<OPTION VALUE="form3">Q uestion 3
</SELECT>

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

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

<DIV ID="form3" style="visibili ty: 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="visibili ty: 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.selectedIn dex].value)
&& x.style){
x.style.visibil ity=x.style.vis ibility=="hidde n"?"visible":"h idden";
}
}

<SELECT NAME="selectLis t" onChange="chang eForm(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.le ngth)
if (what.options[i].selected) {
alert('selected ' + i)
if(document.all ) {
alert('sees document.all')

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

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

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

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

//-->
</script>

</head>

<FORM>
<SELECT NAME="selectLis t" onChange="chang eForm(this.form .selectList)">
<OPTION VALUE="form1" SELECTED>Questi on 1
<OPTION VALUE="form2">Q uestion 2
<OPTION VALUE="form3">Q uestion 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="changeF orm(document.fo rms[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="javas cript">

if(!document.ge tElementById){
document.getEle mentById = function() {
return null;
};
}

function changeForm(what ){
var f;

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

</script>

</head>

<FORM>
<SELECT NAME="selectLis t" onchange="chang eForm(this);">
<OPTION VALUE="form1" SELECTED>Select a question
<OPTION VALUE="form2">Q uestion 2
<OPTION VALUE="form3">Q uestion 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="javas cript">

function changeForm(what ) {
var x;
if((x=document. getElementById( what.options[what.selectedIn dex].value)
&& x.style)
{
x.style.visibil ity=x.style.vis ibility=="hidde n"?"visible":"h idden";
}
}
</script>

</head>

<FORM>
<SELECT NAME="selectLis t" onChange="chang eForm(this)">
<OPTION VALUE="form1" SELECTED>Questi on 1
<OPTION VALUE="form2">Q uestion 2
<OPTION VALUE="form3">Q uestion 3
</SELECT>
<br>

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

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

<DIV ID="form3" style="visibili ty: 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.selectedIn dex].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="javas cript">

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


if(x=document.g etElementById(w hat.options[what.selectedIn dex].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.leng th;i++)
if(document.get ElementById&&do cument.getEleme ntById(what.opt ions[i].value))
document.getEle mentById(what.o ptions[i].value).style.d isplay='none';
var x = what.options[what.selectedIn dex].value;
if(x=document.g etElementById(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="chang eForm(this)">
<OPTION VALUE="form1" SELECTED>Questi on 1
<OPTION VALUE="form2">Q uestion 2
<OPTION VALUE="form3">Q uestion 3
<OPTION VALUE="form4">Q uestion 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

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

Similar topics

2
1471
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 Firefox. I'd appreciate it if someone could help me modify the script so that it would also work with Firefox. The scrolling news can be seen on the page at: http://www.shtetlinks.jewishgen.org/WielkieOczy/
6
1997
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 between the two menus gets bigger. What is the cause of this? Thanks CODE:
1
2151
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
1228
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 Netscape and Firefox?
1
2600
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 Firefox, the cursor is just the "vertical line." Does anyone know why this isn't working with Netscape or Firefox? Thanks!
6
14467
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 postback code, but I have a workaround for that installed (and it looks like the code generated by ASP.NET when it renders the page does the same thing, namely, setting document<). However, the problem still exists under firefox. Has anyone come...
10
2380
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 = navigator.appName;
49
3988
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
2244
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: http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=tn_15507 all three browers successfully run the Flash movie and show the same version of Flash to be installed. However, if I try to use a javascript Flash detection solution, it does
7
1616
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 5.1; en-US; rv:1.0.2) Gecko/20030208 Netscape/7.02 While everythign works great in Firefox and IE, absolutely nothing seems to work with netscape. Is there something I need to change in my browser caps to get it to work in netscape? I want to...
0
9705
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10568
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10323
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10074
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9138
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5516
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3813
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2988
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.