Hide/Show included PHP file
#1
Posted 02 September 2010 - 10:25 AM
Not sure if it should be in the PHP or HTML section, sorry for that.
I use a PHP/JS contact form which is located at my website here:
Contact Form
As you can see at the bottem of the page there are two radio buttons.
These radio buttons should functionate as a hide/show div function, which it does with just some text within the divs.
But now I want to open a different PHP file for each of the two radio buttons.
For example:
"Informatie aanvragen" = checked, show info.php (The contact script related to "Informatie aanvragen") and hide prijs.php (The contact script related to "Prijsindicatie aanvragen") and otherwise if the other radio button is checked.
And if none of the radio buttons is checked, it should show nothing at all.
The problem is that I don't know which commands I should use.
I used 'include ()' now but as you can see it will show both files at the same time if you open the page, but if you choose one of the radio buttons you can see what I want it to work like.
I hope I gave enough information, if not, let me know.
Thanks in advance,
Rokain
#2
Posted 02 September 2010 - 11:17 AM
Rokain, on 02 September 2010 - 10:25 AM, said:
Not sure if it should be in the PHP or HTML section, sorry for that.
I use a PHP/JS contact form which is located at my website here:
Contact Form
As you can see at the bottem of the page there are two radio buttons.
These radio buttons should functionate as a hide/show div function, which it does with just some text within the divs.
But now I want to open a different PHP file for each of the two radio buttons.
For example:
"Informatie aanvragen" = checked, show info.php (The contact script related to "Informatie aanvragen") and hide prijs.php (The contact script related to "Prijsindicatie aanvragen") and otherwise if the other radio button is checked.
And if none of the radio buttons is checked, it should show nothing at all.
The problem is that I don't know which commands I should use.
I used 'include ()' now but as you can see it will show both files at the same time if you open the page, but if you choose one of the radio buttons you can see what I want it to work like.
I hope I gave enough information, if not, let me know.
Thanks in advance,
Rokain
More then likely we would need to see all the code including the php code
#3
Posted 02 September 2010 - 02:06 PM
Because your php scripts need to run on your server they can't be triggered from the browser end using javascript alone. However, ajax would allow you to do this and is not difficult for someone who already knows javascript, so you might want to give that a try ...
W3 Schools AJAX Tutorial
This tutorial will show you how to run a php script triggered with javascript.
Best of luck...
Kirsty
#4
Posted 02 September 2010 - 02:13 PM
#5
Posted 02 September 2010 - 05:39 PM
Also, Thanks Kirsty for your link to the AJAX tutorial, I will take a look at it.
I'm not really an expert with PHP and JS especially not when it comes to contact forms, thats why I took an open source one that has all the features in it which I want to use.
Currently I use this little script to hide and show the two divs:
<script type="text/javascript">
function toggleLayer(val)
{
if(val == 'info')
{
document.getElementById('info').style.display = 'block';
document.getElementById('prijs').style.display = 'none';
}
else if(val == 'prijs')
{
document.getElementById('info').style.display = 'none';
document.getElementById('prijs').style.display = 'block';
}
}
</script>
</head>
<form action="" method="post">
<input id="a1" name="switcher" type="radio" value="info" onclick="toggleLayer(this.checked);" /><label for="a1"> Informatie aanvragen</label> </br>
<input id="a2" name="switcher" type="radio" value="prijs" onclick="toggleLayer(!this.checked);" /><label for="a2"> Prijsindicatie aanvragen</label> </li>
</form>
<div id="info">
<?php
include 'index-info.php';
?>
</div>
<div id="prijs">
<?php
include 'index-prijs.php';
?>
</div>Thanks,
Rokain
#6
Posted 03 September 2010 - 09:19 AM
#7
Posted 03 September 2010 - 12:18 PM
Thanks for your reply, it looks like that is the function I'm looking for.
I have searched around the web for the function to include the PHP files, but I can't get it work with my radio buttons.
I also found this scripts, it works like I want it, but something is wrong with the radiobuttons, they stay checked..
<script type="text/javascript">
function info()
{
$.ajax({
url : "index-info.php",
success : function (data) {
$("#info").html(data);
}
});
}
function prijs()
{
$.ajax({
url : "index-prijs.php",
success : function (data) {
$("#prijs").html(data);
}
});
}
</script>
#8
Posted 03 September 2010 - 12:18 PM
This post has been edited by Rokain: 03 September 2010 - 12:19 PM
#10
Posted 05 September 2010 - 04:57 PM
Rokain, on 03 September 2010 - 12:18 PM, said:
Thanks for your reply, it looks like that is the function I'm looking for.
I have searched around the web for the function to include the PHP files, but I can't get it work with my radio buttons.
I also found this scripts, it works like I want it, but something is wrong with the radiobuttons, they stay checked..
<script type="text/javascript">
function info()
{
$.ajax({
url : "index-info.php",
success : function (data) {
$("#info").html(data);
}
});
}
function prijs()
{
$.ajax({
url : "index-prijs.php",
success : function (data) {
$("#prijs").html(data);
}
});
}
</script> You'll need to set the AJAX request once a radio button has been checked:
see http://www.techiegya...-radio-buttons/
#11
Posted 07 September 2010 - 02:23 PM
I will take a look at it.
rallport, on 05 September 2010 - 04:57 PM, said:
see http://www.techiegya...-radio-buttons/
Help
















