Just hoping to get some assistance. I've created an onclick function for a form to appear which works fine, there are 2 things which I need assistance for.
1. I want the form to remain hidden as default until clicked for it to appear
2. I would also like the form to disappear once it is clicked again
I've kept the code as onmouseout="hide" just so it works (which is works fine)
Is that a good idea? Click on what? You cannot click on a form which is not displayed. Likely to lead to user frustration.
Code:
<script type="text/javascript">
function Toggle(obj) {
var Style = document.getElementById(obj).style;
Style.display = (Style.display == "none") ? "block" : "none";
}
</script>
<div id="MyDiv">
Form Content Goes Here
</div>
<a href="#" onclick="Toggle('MyDiv'); return false;">Toggle</a>
“Expert: a man who makes three correct guesses consecutively.” - Dr. Laurence J. Peter (American "hierarchiologist", Educator and Writer, 1919-1990)
I will re-explain the function.
The word 'login' for example. onclick the login
it will then display a form (THIS CURRENTLY WORKS FINE)
Re-click the word "login"
Form disappears.
Currently I cannot onclick the word login for the form to disppear. I currently have it set on 'onmouseout' which works fine. I just want to be able to click on the word instead. I also want the form as default to appear hidden.
It would seem to me that Philip's code in post #2 can be used for multiple elements - just substitute the id of the element to be toggled for 'MyDiv' in the function call...
Below is my code for the toggle. I want the 'rentvealed', 'buyrevealed' and 'soldrevealed' to appear when they are onclicked, as they will all have different forms...
Code:
<div onclick="toggle()"><strong>Rent</strong></div>
<div onclick="toggle()"><strong>sold</strong></div>
<div id="rentrevealed" style="display: none;">
more code here....
<div id="soldrevealed" style="display: none;">
more code here....
/* Only for the buy revealed single toggle */
<div onclick="toggle()"><strong>Buy</strong></div>
<div id="buyrevealed" style="display: none;">
current code here
</div>
...
function toggle( )
{
var div = document.getElementById("buyrevealed");
div.style.display = ( div.style.display == "block" ) ? "none" : "block";
}
If this is not sufficent, please let me know. Thanks for all your help
I wanted to bring this thread back for some more assistance with the toggle function.
Currently I have 4 seperate toggle functions - lets call them 1,2,3,4
The code of each toggle is as follows
Code:
function toggle(1/2/3/4)
{
var div = document.getElementById("buyrevealed");
div.style.display = ( div.style.display == "block" ) ? "none" : "block";
}
Currently if I click toggle 1, all is good, however if I click toggle 2 while toggle 1 is displayed , Toggle 2 will not appear due to the way it is coded.
I was hoping to get assistance to hide any other toggle unless it is clicked on so there won't be an issue when clicking on any of them