| | |
Toggle div visibility
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Jun 2008
Posts: 13
Reputation:
Solved Threads: 0
Hi all,
I have a div I would like to show and hide.
I've used a script before which works, but now reusing it I can't make it fly. As I can't see where I am going wrong, can anyone else help?
This is the one that works:
...and this is the new version:
I can't see the difference, but the top one works and not the bottom. Pointers please?
I have a div I would like to show and hide.
I've used a script before which works, but now reusing it I can't make it fly. As I can't see where I am going wrong, can anyone else help?
This is the one that works:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<!--script in head tag --> <script type="text/javascript"> <!-- function toggleBox(szDivID, iState) // 1 visible, 0 hidden { if(document.layers) //NN4+ { document.layers[szDivID].visibility = iState ? "show" : "hide"; } else if(document.getElementById) //gecko(NN6) + IE 5+ { var obj = document.getElementById(szDivID); obj.style.visibility = iState ? "visible" : "hidden"; } else if(document.all) // IE 4 { document.all[szDivID].style.visibility = iState ? "visible" : "hidden"; } } // --> </script> <body> <div id="positioned-element25"> <a href="#" onClick="toggleBox('login',1);">Login</a></div> <div id="login"> <form name="fp_login" action="prcs_login.php" method="post"> <table> <!-- abbreviated --> <tr> <td> ... <td> <input type="button" onClick="toggleBox('login',0);" value="Cancel"> </td> </tr> </table> </form> </div>
...and this is the new version:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<script type="text/javascript"> <!-- function toggleBox(szDivID, iState) // 1 visible, 0 hidden { if(document.layers) //NN4+ { document.layers[szDivID].visibility = iState ? "show" : "hide"; } else if(document.getElementById) //gecko(NN6) + IE 5+ { var obj = document.getElementById(szDivID); obj.style.visibility = iState ? "visible" : "hidden"; } else if(document.all) // IE 4 { document.all[szDivID].style.visibility = iState ? "visible" : "hidden"; } } // --> </script> <body> <div id="positioned-element25"> <a href="#" onClick="toggleBox('login',1);">Login</a></div> <div id="login"> <?php include ('mailer.php'); ?> </div> ...
I can't see the difference, but the top one works and not the bottom. Pointers please?
0
#2 Oct 25th, 2009
Ali,
The problem may be that
In other words, the reponsibility for which state becomes set, is external to
I thknk you should ensure that 'login' is initially hidden. This is best achieved with css:
Then at least the Login link will cause it to become visible even if nothing ever hides it again.
Airshow
The problem may be that
toggleBox doesn't actually have a toggle action. It shows/hides a dom element depending on what is passed to it as iState. In other words, the reponsibility for which state becomes set, is external to
toggleBox . If iState is always 1 or always 0 then the visibility state of 'login' will never change.I thknk you should ensure that 'login' is initially hidden. This is best achieved with css:
css Syntax (Toggle Plain Text)
#login { visibility : hidden; }
Airshow
Last edited by Airshow; Oct 25th, 2009 at 7:38 pm.
50% of the solution lies in accurately describing the problem!
•
•
Join Date: Jun 2008
Posts: 13
Reputation:
Solved Threads: 0
In the end I did it like so:
and
...which takes into account your suggestion as well as simplifying the script.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<script type="text/javascript"> <!-- function toggleBox(szDivID, iState) // 1 visible, 0 hidden { if(document.getElementById) //gecko(NN6) + IE 5+ { var obj = document.getElementById(szDivID); obj.style.display = iState ? "block" : "none"; } } // --> </script>
and
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<div id="positioned-element25"> <a href="#" onClick="toggleBox('login',1);">Login</a></div> <div id="login" style="display:none"> <?php include ('mailer.php'); ?> </div>
...which takes into account your suggestion as well as simplifying the script.
![]() |
Similar Threads
- Screen Capture Program (C++)
- PLS I NEED YOUR HELP! Help on Reading and Editing of already Written CODE on php! (PHP)
- Problem in my sliding div...plz help.... (JavaScript / DHTML / AJAX)
- Array Names (JavaScript / DHTML / AJAX)
- Slide In, Slide Out, ala Digg (JavaScript / DHTML / AJAX)
- Toggle div visibility (JavaScript / DHTML / AJAX)
- CSS Div's For Myspace (HTML and CSS)
- update the page without changing it? (Site Layout and Usability)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: mediaplayer fullscreen not working
- Next Thread: Iframe src to change the src of another Iframe
Views: 615 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for JavaScript / DHTML / AJAX
acid2 ajax ajaxcode ajaxhelp animate array automatically autoplay beta boarder box bug button calendar captcha card cart codes column cookies createrange() css cursor date debugger decimal design developer dom download dropdown element enter error events firefox firehose flash focus form frameworks getselection google gwt html htmlform iframe image() index java javascript javascripts jawascriptruntimeerror jquery jsp listbox maps marquee masterpage menu microsoft mimic mp3 mp4 offline onmouseover parameters php player post problem programming progressbar prototype rating redirect regex safari scale scriptlets search select size sources sql starrating text textarea toggle twitter validation variables w3c web website window windowofwords windowsxp xml xspf





