PDA

View Full Version : Show and Hide in php



MSK7
02-04-2009, 06:59 AM
Hi to all,

please tell me any easy php code,

To 'show' and 'hide' a new form file (may be called as "form1.php")
on same current page
by click on radio buttons ?


Any suggession will be appreciated,


Thanks and Regards

JasonDFR
02-04-2009, 07:08 AM
If you want a radio button to control what is displayed on a page without reloading the page, you'll need to use javascript. If I misunderstood what you are asking about, post again.

MSK7
02-04-2009, 08:14 AM
Please suggest,

How javascript codings can help me in easy way, To "show" and "hide" any other new form file (may be called as "form1.php") on my other current page,
on click of radiobuttons.


Thanks & Regards.

JasonDFR
02-04-2009, 08:21 AM
I'm not that great with javascript. You should post your question in the javascript section.

Good Luck!

Schmoopy
02-04-2009, 11:05 AM
It should be in the JavaScript section yes, but here is a stab at it anyway:

HTML: (remember you need to save this as .php as well)



<html>
<head>
<title>Hide Form</title>
<script type="text/javascript">
function showForm(){
var form = document.getElementById("hiddenform");
form.style.display='block'
}


</script>
<style>
#hiddenform{
display:none;
}
</style>
</head>
<body>
Bla bla this text is visible and all my content is here.

<form>
<input type="radio" onclick="showForm();" name="show" value="On">On<br />
<input type="radio" name="show" value="Off">Off
</form>

<div id="hiddenform">
<?php include("form1.php"); ?>
</div>


</body>
</html>


May not be the best way to do it, but gets the job done.

Good Luck!

codeexploiter
02-04-2009, 11:58 AM
Some refinements to Schmoopy's code



<html>
<head>
<title>Hide Form</title>
<script type="text/javascript">
function showForm(flag) {
document.getElementById('hiddenform').style.display = flag === 1 ? 'block' : 'none';
}
</script>
<style type="text/css">
#hiddenform {display: none}
</style>
</head>
<body>
Bla bla this text is visible and all my content is here.
<form>
<input type="radio" onclick="showForm(1);" name="show" value="On">On
<br/>
<input type="radio" name="show" value="Off" onclick="showForm(0);">Off
</form>
<div id="hiddenform">
<?php include("form1.php"); ?>
</div>
</body>
</html>


There is no need for the 'Off' radio button unless we need to hide the form, I have added it here. Additionally some misc changes in JS side. As he mentioned this approach will work under normal circumstances.