flunn Posted June 13, 2007 Share Posted June 13, 2007 I want to put a button on a web page which a user can click on to show some text which will otherwise be hidden. Can I do this using php code? If so, how? regards to all from flunn Quote Link to comment https://forums.phpfreaks.com/topic/55438-solved-is-it-possible-to-use-php-code-to-show-otherwise-hidden-text/ Share on other sites More sharing options...
trq Posted June 13, 2007 Share Posted June 13, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/55438-solved-is-it-possible-to-use-php-code-to-show-otherwise-hidden-text/#findComment-273988 Share on other sites More sharing options...
flappy_warbucks Posted June 13, 2007 Share Posted June 13, 2007 Na thats client side stuff that is, as PHP is Server side that would be a tad difficalt.... you need Javascript. Quote Link to comment https://forums.phpfreaks.com/topic/55438-solved-is-it-possible-to-use-php-code-to-show-otherwise-hidden-text/#findComment-273989 Share on other sites More sharing options...
rab Posted June 13, 2007 Share Posted June 13, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/55438-solved-is-it-possible-to-use-php-code-to-show-otherwise-hidden-text/#findComment-273993 Share on other sites More sharing options...
gijew Posted June 13, 2007 Share Posted June 13, 2007 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> Quote Link to comment https://forums.phpfreaks.com/topic/55438-solved-is-it-possible-to-use-php-code-to-show-otherwise-hidden-text/#findComment-273994 Share on other sites More sharing options...
flunn Posted June 14, 2007 Author Share Posted June 14, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/55438-solved-is-it-possible-to-use-php-code-to-show-otherwise-hidden-text/#findComment-274761 Share on other sites More sharing options...
Nhoj Posted June 14, 2007 Share Posted June 14, 2007 Make sure you study Javascript and not Java... - Or at least make sure you are learning the right one, they're completely different. Quote Link to comment https://forums.phpfreaks.com/topic/55438-solved-is-it-possible-to-use-php-code-to-show-otherwise-hidden-text/#findComment-274762 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.