Results 1 to 4 of 4

Thread: Add password to hide/reveal using display property

  1. #1
    Join Date
    Dec 2004
    Posts
    83
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Add password to hide/reveal using display property

    Hey guys,
    Is it possible to add a password prompt when using display property with some js to hide/reveal content?

    I know it's kind of pointless as the content will be in source code, but I need it for something very basic for a mobile page.

    Would really appreciate the help. Here's what I'm using for hide/reveal:
    <div id="hideaway" style="display:none;">Here's the hidden content</div>

    <a href="javascript:;" onClick="document.getElementById('hideaway').style.display='block';">Reveal hidden content</a>

    <a href="javascript:;" onClick="document.getElementById('hideaway').style.display='none';">Hide content again</a>


    How can I add password to this? I would really appreciate any help. Thanks.
    Last edited by viktor; 01-07-2012 at 03:00 PM. Reason: resolved

  2. #2
    Join Date
    Jun 2011
    Location
    Pearl of the East
    Posts
    54
    Thanks
    1
    Thanked 2 Times in 2 Posts

    Default

    is this what you are looking for, sir?

    Code:
    <div id="hideaway" style="display:none;">Here's the hidden content</div>
    
    <a href="javascript:void(0);" onClick="rdfShow('hideaway')">Reveal hidden content</a>
    
    <a href="javascript:void(0);" onClick="rdfHide('hideaway')">Hide content again</a>
    
    
    <script type="text/javascript">
    var pass = '1234';
    
    function rdfHide(obj){
    	var popup = prompt("What's the password?", "");
    	
    	if(popup==pass)
    		document.getElementById(obj).style.display = 'none';
    	else
    		alert('Wrong password!');
    }
    
    function rdfShow(obj){
    	var popup = prompt("What's the password?", "");
    	
    	if(popup==pass)
    		document.getElementById(obj).style.display = 'block';
    	else
    		alert('Wrong password!');
    }
    </script>

  3. #3
    Join Date
    Dec 2004
    Posts
    83
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    Absolutely! Perfect. Thanks a lot, really do appreciate it.

  4. #4
    Join Date
    Jun 2011
    Location
    Pearl of the East
    Posts
    54
    Thanks
    1
    Thanked 2 Times in 2 Posts

    Default

    anytime sir,. now edit this thread and make it RESOLVED sir,. ^_~

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •