Jump to content

[SOLVED] Is it possible to use php code to show otherwise hidden text?


Recommended Posts

You could, but it means another trip back to the server. Javascript would be a better option. Or, if you really want to hide the text (ie; not visable in soure either) you'd be best to use a combination of php and Javascript. This sort of interaction is commonly refered to as Ajax.

It wouldn't be difficult at all, with some Javascript knowledge.

 

<html>
<body>

<script type="text/javascript">
function unhide() {
  x = document.getElementById("hidden");
  x.style.visibility = "visible";
}
</script>

<p id="hidden" style="visibility: hidden;">This was hidden</p>
<input type="button" onclick="unhide()" value="Show the hidden!" />

</body>
</html>

 

If you want to retrieve data from a database or so, look into AJAX.

I know this is the PHP forum and yes you could do this using PHP. In my eyes you could do that one of two ways. Store the hidden state in a session or a database. Either way it would require the page to reload to display the contents. It could really take forever. The JS or Ajax is really simple.

 

<a href="javascript:void(0);" onclick="document.getElementById('DIV_NAME').style.display='';">Show me</a>
<a href="javascript:void(0);" onclick="document.getElementById('DIV_NAME').style.display='none';">Hide me</a>

<div id="DIV_NAME" style="display:none;">Look at me ma!</div>

Many thanks to thorpe, flappy_warbucks, rab,and gijew for their responses to my question yesterday about using php to show hidden text.  I wasn't really surprised to hear that Java would be a better way of doing this than php but I was hoping there was a straightforward method using php because I don't know anything about Java (and am a near-beginner with php!).  I tried rab's code and found it worked fine on its own, but I wasn't able to integrate into my own php code successfully. So I've decided to do without a "show text" button for the time being. Anyway I'm very grateful for the replies which were interesting and informative — and which convinced me I'm going to have to sit down and learn some Java before long.

 

regards to all from flunn

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.