Forum Moderators: open

Message Too Old, No Replies

js toggle = doubleclick - how to remove?

remove double click

         

Salami1_1

3:27 am on Oct 4, 2010 (gmt 0)

10+ Year Member



Hi,

I'm using a javascript to toggle content (show / hide) however for some reason I do not get users (all browsers) need to double click the link to actually toggle the content.
JS:

function toggleVisibility(controlId) {
if (document.getElementById) { // DOM3 = IE5, NS6
var control = document.getElementById(controlId);
if(control.style.display == "inline" || control.style.display == "")
control.style.display = "none";
else
control.style.display = "inline";
}
else {
if (document.layers) { // Netscape 4
if(document.controlId.display == "inline" || document.controlId.display == "")
document.controlId.display = "none";
else
document.controlId.display = "inline";
}
else { // IE 4
if(document.all.controlId.style.display == "inline" || document.all.controlId.style.display == "")
document.all.controlId.style.display = "none";
else
document.all.controlId.style.display = "inline";
}
}
}



Link:
<a href="javascript:toggleVisibility('feedbackform')">Feedback form</a>
<div id="feedbackform">
some form
</div>

css:

#feedbackform{
display: none;
}


Can somebody explain me how to remove this behaviour and just make it 'one-click'?

Thank you.

Best regards,

daveVk

4:38 am on Oct 4, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Remove the CSS rule and declare

<div id="feedbackform" style="display:none" >

The CSS rule does NOT effect the value of style.display so on first click your code does detect that the div is hidden.

Div elements are display "block" not "inline"

Toggling between "none" and "" is better idea, assuming no CSS rule.

if(control.style.display == "")
control.style.display = "none";
else
control.style.display = "";

Salami1_1

6:36 am on Oct 4, 2010 (gmt 0)

10+ Year Member



awesome that works perfect. thanks a lot!