Page 1 of 2
Action on Image Clicked
Posted: Fri Jul 20, 2007 7:18 am
by TryAgain2
I want to change the contents of layers when users click on icons. For example, click on the News icon and the main panel displays news from the database.
How can you know when an icon has been clicked on? (the icon is a roll-over image) I don't want to link to another page.
Thanks in advance.
Posted: Fri Jul 20, 2007 7:41 am
by arturm
Code: Select all
onClick='yourJavaScriptFunction();'
Posted: Fri Jul 20, 2007 10:38 pm
by TryAgain2
Thanks, I'm programming in PHP, so that should work also? I'll try it.
Posted: Sun Jul 22, 2007 5:14 pm
by califdon
Umm, PHP is server-side script...it can't do anything about what the user may click on after the HTML has been delivered to the browser. You have to do that in client-side script!
Posted: Sun Jul 22, 2007 8:40 pm
by TryAgain2
Thanks Califdon. I'll look at handling that with Javascript. Is that how PHP content management systems, like PHP Nuke handle button clicks?
Posted: Sun Jul 22, 2007 9:14 pm
by superdezign
Anything server side handles clicks like clicks should be handled.
Posted: Sun Jul 22, 2007 9:55 pm
by TryAgain2
Hi Superdezign, I don't understand you. Are you saying that PHP can handle clicks? How is it done?
Posted: Sun Jul 22, 2007 9:59 pm
by superdezign
By going to a different page.
Posted: Sun Jul 22, 2007 10:09 pm
by TryAgain2
A man of few words.
I don't want to goto a different page, I want to change the current page, like PHP content management systems do. How do they do that?
Posted: Sun Jul 22, 2007 10:13 pm
by superdezign
I don't use a CMS, but I have used Drupal before, and if any of them are similar, they DO go to a different page. The pages may look extremely similar, or be the same physical file with POST/GET requests, but it's still a different page.
Server-side code delivers content. Client-side code responds to events.
Posted: Mon Jul 23, 2007 7:29 am
by TryAgain2
Do you have an example of how it would be done -say, to change the contents of a layer when a button is clicked?
Posted: Mon Jul 23, 2007 7:38 am
by superdezign
Code: Select all
if(isset($_GET['a']) && $_GET['a'] == 'login')
{
echo '<form id="login" method="post"><input type="text" /><input type="password" /><input type="submit" /></form>';
}
else
{
echo '<p>Would you like to <a href="?a=login">login to your account</a>?</p>';
}
Posted: Tue Jul 24, 2007 9:48 am
by timgolding
php will not directly handle the clicks but instead can be used to echo some Java script that will handle the clicks.
I think everyone is confused because 'goto a different page' and 'change the current page' are the same thing?
Can you differentiate for us?
Posted: Tue Jul 24, 2007 10:27 am
by superdezign
timgolding wrote:php will not directly handle the clicks but instead can be used to echo some Java script that will handle the clicks.
I think everyone is confused because 'goto a different page' and 'change the current page' are the same thing?
Can you differentiate for us?
"Changing" a page is client-side and is handled by the client's browser and client-side code. Serving a different page is handled server-side and is controlled by the server. I'm fairly sure that the CMS being referred to is not ruled by JavaScript and does not "change" pages, but serves a different one.
A page that looks just like another is still a different page. POST requests and GET requests are a part of a page, so even if it is the same physical file, it is still a different page. The most obvious difference is that when you serve a new page, pressing the back button in your browser will take you back to the previous one, but when you "change" a page with JavaScript, the back button would send you farther than you may expect.
Posted: Wed Jul 25, 2007 5:46 am
by TryAgain2
It works, but flickers when the page reloads. Here is what I did:
// For the button
a href="index.php?Content=consulting"...
This reloads the same page:
<?php
if(isset($_GET['Content']) && $_GET['Content'] == 'consulting')
{
echo 'Test worked!';
}
else
{
echo 'Didnt work';
}
When the "Consulting" button is clicked the page flickers and the success message is shown.