Newsgroups: comp.lang.javascript
From: "RobG" <rg...@iinet.net.au>
Date: 5 May 2005 20:35:51 -0700
Local: Thurs, May 5 2005 11:35 pm
Subject: Re: JavaScript Document Code Not Cross Platform
bradwiseath...@hotmail.com wrote: Missing DOCTYPE - that has ramifications here (see below), suggest: > I have code that works in IE 6 but does not work in FireFox 1.0.2, how > can I change it so it works in both browsers? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" > <html> The language attribute is depreciated, keep the required type > <head> > <script language="JavaScript" type="text/JavaScript"> attribute. > function AttributeSelected() document.forms['testspit'].elements['lsbRA'].options; > { > var selectVal = In quirksmode (sans DOCTYPE) IE handles this, Firefox doesn't. If var selectVal = document.forms['testspit'].elements['lsbRA']; will fix the issue if 'lsbRA' is a single select - take care, if the Adding '.options' on the end returns a collection of the options, which Since 'lsbRA' is a multiselect, you need to iterate through the options var selectVal = document.forms['testspit'].elements['lsbRA']; > if (selectVal.value == 'Item1') becomes: if (selectVal[i].value == 'Item1') > { Here you are using getElementById on elements that have no ID. IE > document.getElementById('text2').style.visibility='visible'; treats names and IDs as virtually the same thing, Firefox doesn't (because they are very different things but overlap somewhat in purpose). ID and NAME share the same namespace, so if you can't have different elements with the same name & id. You can, in some circumstances, have the same name on multiple elements. The quick 'n dirty solution here is to put the same ID on your elements > document.getElementById('spnlabel').style.visibility='visible'; Add a couple of curly braces to close the added for and if loops. > } > else > { > document.getElementById('text2').style.visibility='hidden'; > document.getElementById('spnlabel').style.visibility='hidden'; > } } > } <input name="text1" id="text1" ... > > </script> > </head> > <body> > <form name="testspit" method="post" action=""> > <div id="divPlace" style="width:90%;left:10px;top:40px"> > <select multiple id="lsbRA" onChange="AttributeSelected();" > > <option value="Item1">Item 1</option> > <option value="Item2">Item 2 </option> > </select> > <br/><br/> > <input name="text1" type="text" value="text1" size="20"> > <br/><br/> <input name="text2" id="text2" ... > > <span id="spnlabel" style="overflow:hidden"> > - > </span> > <span id="spntext" style="overflow:hidden"> > <input name="text2" type="text" value="text2" size="20"> > </span> PS. The logic seems strange, but I'll leave that alone... unless it > </div> > </body> > </html> > Thanks. isn't doing whatever you expect it to. As it is, it may cause flickering for some users. -- You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||