PDA

View Full Version : Resolved Add password to hide/reveal using display property



viktor
01-02-2012, 08:19 PM
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.

regicidedelferoz
01-03-2012, 05:51 AM
is this what you are looking for, sir?



<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>

viktor
01-03-2012, 04:09 PM
Absolutely! Perfect. Thanks a lot, really do appreciate it.

regicidedelferoz
01-04-2012, 03:00 AM
anytime sir,. now edit this thread and make it RESOLVED sir,. ^_~