Action on Image Clicked

JavaScript and client side scripting.

Moderator: General Moderators

TryAgain2
Forum Newbie
Posts: 17
Joined: Tue Jun 12, 2007 10:05 pm

Action on Image Clicked

Post 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.
User avatar
arturm
Forum Commoner
Posts: 86
Joined: Fri Apr 13, 2007 8:29 am
Location: NY
Contact:

Post by arturm »

Code: Select all

onClick='yourJavaScriptFunction();'
TryAgain2
Forum Newbie
Posts: 17
Joined: Tue Jun 12, 2007 10:05 pm

Post by TryAgain2 »

Thanks, I'm programming in PHP, so that should work also? I'll try it.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Post 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!
TryAgain2
Forum Newbie
Posts: 17
Joined: Tue Jun 12, 2007 10:05 pm

Post 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?
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Anything server side handles clicks like clicks should be handled.
TryAgain2
Forum Newbie
Posts: 17
Joined: Tue Jun 12, 2007 10:05 pm

Post by TryAgain2 »

Hi Superdezign, I don't understand you. Are you saying that PHP can handle clicks? How is it done?
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

By going to a different page.
TryAgain2
Forum Newbie
Posts: 17
Joined: Tue Jun 12, 2007 10:05 pm

Post 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?
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post 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.
TryAgain2
Forum Newbie
Posts: 17
Joined: Tue Jun 12, 2007 10:05 pm

Post 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?
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post 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>';
}
timgolding
Forum Newbie
Posts: 14
Joined: Tue Jul 24, 2007 9:02 am

Post 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?
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post 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.
TryAgain2
Forum Newbie
Posts: 17
Joined: Tue Jun 12, 2007 10:05 pm

Post 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.
Post Reply