Web Design Forum: Hide/Show included PHP file - Web Design Forum

Jump to content

WDF
WDF Premium Memberships Reseller Hosting
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Hide/Show included PHP file Rate Topic: -----

#1 User is offline   Rokain 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 11
  • Joined: 31-August 10
  • Reputation: 0
  • Gender:Male
  • Experience:Beginner
  • Area of Expertise:I'm Learning

Posted 02 September 2010 - 10:25 AM

Hello,

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
0

#2 User is offline   webdesigner93 

  • Web Guru
  • PipPipPipPipPip
  • Group: Members
  • Posts: 1,858
  • Joined: 22-September 09
  • Reputation: 212
  • Gender:Male
  • Experience:Web Guru
  • Area of Expertise:Web Developer

Posted 02 September 2010 - 11:17 AM

View PostRokain, on 02 September 2010 - 10:25 AM, said:

Hello,

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 :)
0

#3 User is offline   Tangled Frog 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 5
  • Joined: 17-August 10
  • Reputation: 1
  • Gender:Female
  • Location:Edinburgh
  • Experience:Intermediate
  • Area of Expertise:Web Designer

Posted 02 September 2010 - 02:06 PM

Hi Rokain,

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
0

#4 User is offline   DomH 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 14
  • Joined: 21-July 10
  • Reputation: 0

Posted 02 September 2010 - 02:13 PM

Alternatively, include both PHP files at the start into 2 seperate divs and in the OnClick of the radio button, call a JS function which shows 1 div and hides others:)
0

#5 User is offline   Rokain 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 11
  • Joined: 31-August 10
  • Reputation: 0
  • Gender:Male
  • Experience:Beginner
  • Area of Expertise:I'm Learning

Posted 02 September 2010 - 05:39 PM

Thanks for the replys!

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
0

#6 User is online   rallport 

  • Web Guru
  • PipPipPipPipPip
  • Group: Members
  • Posts: 3,503
  • Joined: 03-January 10
  • Reputation: 247
  • Gender:Male
  • Location:England, UK
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 03 September 2010 - 09:19 AM

Could do this in 2 seconds using the jquery .load function. This way, you can include which ever php file you require on a the click event.
0

#7 User is offline   Rokain 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 11
  • Joined: 31-August 10
  • Reputation: 0
  • Gender:Male
  • Experience:Beginner
  • Area of Expertise:I'm Learning

Posted 03 September 2010 - 12:18 PM

Hi rallport,

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> 

0

#8 User is offline   Rokain 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 11
  • Joined: 31-August 10
  • Reputation: 0
  • Gender:Male
  • Experience:Beginner
  • Area of Expertise:I'm Learning

Posted 03 September 2010 - 12:18 PM

Something went wrong while posting, sorry for double post.

This post has been edited by Rokain: 03 September 2010 - 12:19 PM

0

#9 User is offline   Rokain 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 11
  • Joined: 31-August 10
  • Reputation: 0
  • Gender:Male
  • Experience:Beginner
  • Area of Expertise:I'm Learning

Posted 05 September 2010 - 09:38 AM

Anyone knows another easy solution?
0

#10 User is online   rallport 

  • Web Guru
  • PipPipPipPipPip
  • Group: Members
  • Posts: 3,503
  • Joined: 03-January 10
  • Reputation: 247
  • Gender:Male
  • Location:England, UK
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 05 September 2010 - 04:57 PM

View PostRokain, on 03 September 2010 - 12:18 PM, said:

Hi rallport,

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/
0

#11 User is offline   Rokain 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 11
  • Joined: 31-August 10
  • Reputation: 0
  • Gender:Male
  • Experience:Beginner
  • Area of Expertise:I'm Learning

Posted 07 September 2010 - 02:23 PM

Thanks!

I will take a look at it. :)


View Postrallport, on 05 September 2010 - 04:57 PM, said:

You'll need to set the AJAX request once a radio button has been checked:

see http://www.techiegya...-radio-buttons/

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users