Author Topic: How does showHidden input work?  (Read 1131 times)

AyRestaurant

  • Regular Member
  • **
  • Posts: 25
  • Karma: 0
    • View Profile
How does showHidden input work?
« on: January 06, 2011, 10:01:29 PM »
I have this input that is hidden and I want to show it with a button click.

Someone recommended this:


<script type="text/javascript">
function showHidden(id)
{
alert(
document.getElementById(id).value
);
//Sorry, yahoo was cutting it off
}
</script>

onclick call this function and send it the id of the hidden input. for example if you had
<input type="hidden" id="h" value="show me" />

then your call should look like this
<input type="button" value="click me" onclick="showHidden('id')" />


but it does not work...


someone else told me to add this somewhere:

if(document.getElementById(id).getAttribute('type') == 'hidden') {
   document.getElementById(id).setAttribute('type', 'text');
}


neither work... plz help..

AyRestaurant

  • Regular Member
  • **
  • Posts: 25
  • Karma: 0
    • View Profile
Re: How does showHidden input work?
« Reply #1 on: January 07, 2011, 12:16:46 AM »
problem solved
PHP Code: [Select]
<html>

<
head>


<
meta name="Content-Script-Type" content="text/javascript">
<
meta name="Content-Style-Type" content="text/css">



<
style type="text/css">
.
hidden {
display:none;
}
</
style>
<
script type="text/javascript">
function 
showHidden(obj){
var 
thisP=obj.parentNode.nextSibling;
while(
thisP.nodeName!='P'){thisP=thisP.nextSibling}
var 
allP=obj.parentNode.parentNode.getElementsByTagName('p'), i=0P;
while(
P=allP[i++]){
if(
P.className=='hidden'){
P.style.display=P==thisP?P.style.display=='none'||P.style.display==''?'block':'none':'none';
}
}
}
</script>


</head>


<p>Introduction 2 text goes here
 <span onclick="showHidden(this)"><input type="button" value="More"/></span></p>
    <p class="hidden">
Sample hidden text 2 goes here
    </p>



</html>