•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 373,466 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,959 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 1888 | Replies: 1
![]() |
•
•
Join Date: Feb 2008
Location: Colorado
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
I am having trouble with a piece of javascript code that expands blocks of text. For example, when you click the title, the text under it will expand. I am fairly new to javascript but it looks like the code bassically re-writes the link in the html so that when you press the title again, it will collapse the text.
Here is the javascript code...
Here is the HTML code...
The problem that I am having is that when you open the page in Mozilla Firefox or Safari, the boxes do not expand and collapse properly after you have expanded and collapsed it once. The code works perfectly fine in IE7. I am really stuck and cannot figure out why the java code would work fine in IE and not Firefox/Safari.
If anyone has any advice on how to accomplish this or how to tweak my current code to work on other browsers it would be very appreciated.
Here is the javascript code...
function expand(ID,name)
{
document.getElementById('item'+ID).style.display = 'block';
document.getElementById('expander'+ID).innerHTML =
'<a href="javascript:collapse('+ID+',\''+name+'\')" title="Collapse"><img alt="less" src="images/arrow_back.gif" width="20" height="10" class="no_border" /> <span id="expander1" class="style_heading3">'+name+'</span><br /></a>';
}
function collapse(ID,name)
{
document.getElementById('item'+ID).style.display = 'none';
document.getElementById('expander'+ID).innerHTML =
'<a href="javascript:expand('+ID+',\''+name+'\')" title="Expand"><img alt="more" src="images/arrow.gif" width="20" height="10" class="no_border" /> <span id="expander1" class="style_heading3">'+name+'</span><br /></a>';
}Here is the HTML code...
<div id="expander1" class="expander" style="display: inline"> <a href="javascript:expand(1, 'TITLE')" title="Expand"> <img alt="more" src="images/arrow.gif" width="20" height="10" class="no_border" /> <span class="style_heading3">TITLE</span><br /> </a> </div> <div id="item1" style="display: none"> Expanded text goes here </div>
The problem that I am having is that when you open the page in Mozilla Firefox or Safari, the boxes do not expand and collapse properly after you have expanded and collapsed it once. The code works perfectly fine in IE7. I am really stuck and cannot figure out why the java code would work fine in IE and not Firefox/Safari.
If anyone has any advice on how to accomplish this or how to tweak my current code to work on other browsers it would be very appreciated.
Last edited by nova706 : Feb 27th, 2008 at 11:30 pm.
•
•
Join Date: Dec 2004
Location: London or Slovakia
Posts: 1,899
Reputation:
Rep Power: 9
Solved Threads: 216
I used something like this 2-3 years ago on one of my school assigmnets. Maybe it will help you...
Script in the head of html
Inside body of html
Script in the head of html
html Syntax (Toggle Plain Text)
<script type="text/javascript"><!--function to hide/show submenu options--> (document.getElementById ? DOMCapable = true : DOMCapable = false); function show(menuName) { if (DOMCapable) { if(document.getElementById("menu1choices").style.visibility=="hidden") { document.getElementById("menu1choices").style.display="block"; document.getElementById("menu1choices").style.visibility="visible"; } else { document.getElementById("menu1choices").style.display="none"; document.getElementById("menu1choices").style.visibility="hidden"; } } } function hide(menuName)<!--Function to hide submenu if any other option from main menu selected--> { if (DOMCapable) { document.getElementById("menu1choices").style.display="none"; document.getElementById("menu1choices").style.visibility="hidden"; } } </script>
Inside body of html
html Syntax (Toggle Plain Text)
<div id="menu1" onClick="show('menu1choices');"> <p class="black_link" style="cursor: pointer;">Quiz</p></div> <div id="menu1choices" style="display: block; visibility: visible;"> <table border="0"> <tbody><tr> <td><a href="quiz1.html" target="main" class="black_smaller">Quiz 1</a></td> </tr> <tr> <td><a href="test.html" target="main" class="black_smaller">Quiz2</a></td> </tr> </tbody> </table> </div> <script type="text/javascript"> if (DOMCapable) { show("menu1"); } </script>
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)
If we helped you to solve your problem, answered your question please mark your post as SOLVED.
Publilius Syrus
(~100 BC)
If we helped you to solve your problem, answered your question please mark your post as SOLVED.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb JavaScript / DHTML / AJAX Marketplace
•
•
•
•
ads adsense cross-browser javascript menu with few lines of code firefox firefox background-position problem solved google html javascript javascript delete all rows from table in javascript show overflow of text by "..." javascript smooth scrolling scroll smoothly window document position javascript tab menu with rounded corners generator link prevent javascript menu from getting hidden under flash movies preventing the delay when src attribute of the images set via javascript revenue split text into substrings seperated more than one character text unit update panel scroll problem
- javascript works in IE but not working in firefox (JavaScript / DHTML / AJAX)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: document.getElementById problem
- Next Thread: SVG to gif



Linear Mode