Can someone please help. I have a rollover image and when you click it takes you to a page. But I want it to remain on the same page. I want it to display data from a db. But should appear on the same page where the button is. So on click I want it display the echo in my function. Not on body load but only on the click event. I tried using a session but when the page loads it still appears. my code kinda looks like this. "onClick="<? test(); ?>" " inside that a href of the rollover please help :(

Recommended Answers

All 3 Replies

Hi there,

The problem is that php is pre-processed, ie all of the php code is run before a page is served to the client and therefore, you cannot add interactivity to a page (like with the onXXXX event handlers of html elements) with php. You need to use a client side scripting language like Javascript. If you really need to use server side stuff to do the job, then you'll have to use AJAX to handle the request.

Are there any other techniques that can be used

Well, not really. You need to handle the intitial request (the client clicking on the button/link) with a javascript or other client side scripting language. You can not call a php function directly from that event, if you need to run a php function, you'll need to write an AJAX function (which is javascript, but in a unique methodology) to request that function be run by the server.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.