Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 23rd, 2009, 04:22 PM
Authorized User
 
Join Date: Aug 2003
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
Default Change css display value with JS

Is there a limitation on non-IE browsers with the following?

Code:
 if(busLocationTypeValue == "n")
 {
  document.getElementById("divNonCentralLocation").style.display = 'block';
  document.getElementById("divCentralLocation").style.display = 'none';
  document.getElementById("cBusLocation").value = '';
 }
 else {
  document.getElementById("divNonCentralLocation").style.display = 'none';
  document.getElementById("divCentralLocation").style.display = 'block';
  document.getElementById("ncBusLocation").value = '';
 }
based on busLocationTypeValue I'm hiding or displaying one div or another. This code works in IE but nothing else.

thanks

Darin
 
Old January 23rd, 2009, 04:28 PM
Authorized User
 
Join Date: Aug 2003
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry to bother. Reversing two lines makes it work now.

Code:
if(busLocationTypeValue == "n")
 {
  document.getElementById("divNonCentralLocation").style.display = 'block';
  document.getElementById("divCentralLocation").style.display = 'none';
  document.getElementById("cBusLocation").value = '';
 }
 else {
  document.getElementById("divCentralLocation").style.display = 'block';
  document.getElementById("divNonCentralLocation").style.display = 'none';
  document.getElementById("ncBusLocation").value = '';
 }
 
Old January 23rd, 2009, 04:31 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Nope, I do this all the time.

Have you debugged??

Have you checked that busLocationTypeValue really *IS* only and exactly n in those other browsers?

&&&&&&&&&&&&&&&&&&&&&

Incidentally, you can write that more compactly:
Code:
 var isN = (busLocationTypeValue == "n");
 document.getElementById("divNonCentralLocation").style.display = isN ? 'block' : 'none';
 document.getElementById("divCentralLocation").style.display = isN ? 'none' : 'block'
 document.getElementById( (isN ? "c" : "nc" ) + "BusLocation").value = '';
 
Old January 23rd, 2009, 04:33 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Quote:
Originally Posted by lcsgeek View Post
Sorry to bother. Reversing two lines makes it work now.
WEIRD! Can't see why that would matter. Unless the two divs (or whatever they are) are somehow nested???





Similar Threads
Thread Thread Starter Forum Replies Last Post
Change background color using CSS pigtail Javascript How-To 9 April 4th, 2010 11:13 AM
Block css/js files dipanjan22 ASP.NET 1.x and 2.0 Application Design 3 August 20th, 2007 12:08 PM
help for a code to change css themes masita CSS Cascading Style Sheets 0 May 30th, 2007 03:12 PM
change styles of text Box conditionally using CSS toshi CSS Cascading Style Sheets 1 May 26th, 2006 08:49 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.