aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Hiding/Showing div elements using Javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Hiding/Showing div elements using Javascript" Watch "Hiding/Showing div elements using Javascript" New topic
Author

Hiding/Showing div elements using Javascript

John Zwick
Ranch Hand

Joined: Mar 02, 2009
Posts: 34
Can anyone explain why the following does not work?


However, this code works?


I dont understand why the second set of code works but the first doesnt.

Can someone please explain?

thanks!
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9305
    
  17

Why are there double equals in your assignments ??



should be



SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Ankit is correct

You can make the code more compact:


Readable:


or

Harder to read, but more compact


Eric
John Zwick
Ranch Hand

Joined: Mar 02, 2009
Posts: 34
wow you guys are awesome!

thanks a lot!
John Zwick
Ranch Hand

Joined: Mar 02, 2009
Posts: 34
I have another question related to this:


The javascript is triggered by a dropdown list onchange event like so:


However this becomes a problem if the default selection of the dropdown is something else like "insert" or "message". Since there is no onchange event to trigger the javascript function, the appropriate div elements are not shown. How do I check for this when the page loads? Will have have to create another javascript function to check what the current value of the dropdown list is and show the appropriate div elements?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61432
    
  67

Please do not show server-side markup in an HTML forum. Expand the markup to its generated HTML.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
John Zwick
Ranch Hand

Joined: Mar 02, 2009
Posts: 34
Bear Bibeault wrote:Please do not show server-side markup in an HTML forum. Expand the markup to its generated HTML.


oops, my bad

Here is the generated HTML:
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
use onblur instead of onchange or call your function onload of the page.

Eric
 
wood burning stoves
 
subject: Hiding/Showing div elements using Javascript