| | |
Expandable Javascript Text Block Problem
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Feb 2008
Posts: 2
Reputation:
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...
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
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...
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<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 28th, 2008 at 12:30 am.
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)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
![]() |
Similar Threads
- 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
| Thread Tools | Search this Thread |
acid2 ajax ajaxcode ajaxexample ajaxhelp ajaxjspservlets animate automatically beta box browser bug captchaformproblem checkbox close codes createrange() css cursor debugger decimal dependent disablefirebug dom download dropdown editor element engine error events explorer ext file firefox form forms frameworks getselection google gwt gxt hiddenvalue highlightedword hint html htmlform ie7 ie8 iframe index internet java javascript javascripthelp2020 jawascriptruntimeerror jquery jsf jsfile jsp jump listbox maps masterpage math media microsoft mp4 object onmouseoutdivproblem onreadystatechange paypal pdf php player position programming progressbar prototype redirect regex runtime safari scale scriptlets search security select size software sql text textarea unicode w3c window windowofwords windowsxp wysiwyg \n






