Hi guys,

How can I call a php-function by using the onclick-event?

Thanx for help.

Thomas
You can't PHP is serverside and javascript (onclick) is client side.
While using AJAX techniques you can request output of a php script
Can I do it by using a javascript?
Example:

<a href="index.php" onclick="document.write('functions.php')">TEST</a>

Thanx for help,

Thoaren
AJAX is javascript. Look for a tutorial.

Perhaps you don't need AJAX (depends on your prblem) Probably you can do it by invoking (submit0 another page?
When you tell us what you want to make, maybe we can help you to solve the problem or we give you some ideas.
I mean: why you need a client-side event for PHP?
Thoaren, "serverside" means that calling a PHP function, or script, would always require a reload of the page. AJAX is a technique to load a file (just like reloading), but then within the current page. However, in most cases there's a better workaround than AJAX. So in interest of performence, and in interest of good code, please tell us your exact problem.

Welcome to PHPhulp by the way.
I have a header.php with menu in it.
When clicked on one of the menu-items, header.php and the corresponding page from the menu is been included in index.php.
This a will not change.

So this is the situation description:

*index.php:
-includes header.php
-includes corresponding page from de menu in header.php
-includes footer.php

*header.php with menu

*corresponding pages, let's say: page01.php and page02.php

This I will not change.

Now I want to change the backgroundimage of a cell in the menu when the corresponding page, let's say page02.php is loaded in the index.php. The backgroundimage of the other menu-items must be change to standard then. I want to do the same when page01.php is loaded in index.php. Also the backgroundimage of the other menu-items must be change to standard then.


Thanx for help.

Thoaren
Well, you can do that by using only Javascript.


<script>
function BackToNormal() {
document.getElementById('name1').style.background='url(normal.gif) no-repeat;';
document.getElementById('name2').style.background='url(normal.gif) no-repeat;';
document.getElementById('name3').style.background='url(normal.gif) no-repeat;';
}

function LoadNewImage(element, url) {
element.style.background='url(' +url+ ') no-repeat;';
}
</script>

<something id="name1" onClick="BackToNormal(); LoadNewImage(this, 'something.gif');">

<something id="name2" onClick="BackToNormal(); LoadNewImage(this, 'somethingelse.gif');">



Just be smart with the names and Javascript functions. This was just an example.
Spreken wij geen Nederlands op PHPhulp.nl?
Of zijn we internationaal gegaan en heeft niemand me wat verteld?
Hij begon in het engels ;)

Reageren