javascript toggle doubleclick to one click

Discussion in 'JavaScript' started by Salami1_1, Oct 3, 2010.

  1. #1
    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";        
    		}
    	}
    }
    
    
    Code (markup):
    Link:
    <a href="javascript:toggleVisibility('feedbackform')">Feedback form</a>
    <div id="feedbackform">
    some form
    </div>

    css:
    
    #feedbackform{
        display: none;
    }
    
    Code (markup):
    Can somebody explain me how to remove this behaviour and just make it 'one-click'?

    Thank you.

    Best regards,
     
    Salami1_1, Oct 3, 2010 IP
  2. guardian999

    guardian999 Well-Known Member

    Messages:
    376
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #2
    Something like this
    <a href="javascript:void(0);" onclick="javascript:toggleVisibility('feedbackform')">Feedback form</a>
    <div id="feedbackform">
    some form
    </div>
    
    Code (markup):
     
    guardian999, Oct 3, 2010 IP
  3. Salami1_1

    Salami1_1 Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi,
    thanks but doesn't work..
    I also tried making the link just <a href="#" onclick="....."> but doesn't work either..

    I cant post link to the website here but it is unlocksamsungonline . eu / feedback.php

    B.r.
     
    Salami1_1, Oct 3, 2010 IP
  4. Salami1_1

    Salami1_1 Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    problem fixed:

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

    and

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

    Best regards,
     
    Salami1_1, Oct 3, 2010 IP