Forum Moderators: open

Message Too Old, No Replies

Using JS onClick to run PHP script on the server - no refresh

         

hatman

2:48 pm on Aug 5, 2005 (gmt 0)

10+ Year Member



Hi,
I have been trying to figure this out for a while now. i have also tried possible workarounds for this but they don't quite fit my needs.

Here is what I am trying to accomplish:
Say I have a list of entryes and each entry has a couple of checkboxes associated with it for different values/options that can be checked on/off.
I want to be able to dynamically save a value in a database of a specific entry by checking a checkbox (pressing a button or whatever). I want to be able to run a (PHP) script on the server with no output - it would just be an SQL UPDATE statement to update the value assigned to the checkbox (button or whatever) of the specific entry, but (here comes the part I'm having difficulty figuring out) I don't want to press an update button or refresh the page and I dont want a flash of a popup window (open/close) to run the script.

With refresh it would be easy, I'd have a statement at the top of a page to capture the name and value of the checkbox and run the query to update the DB before the page loads to read the DB for output.

Using a popup window would also be easy just would need to shift the focus so it doesn't run in front of the page but you'd still get a little flash of the window - especially on a slower machine.

What i want to accomplish is similar to the Netflix and Blockbuster site where you can rate movies by clikcing on a star. When you click the star you can see that the browser did something but there is no refresh and the value you clicked on is automatically saved.

Is this something that could potentially be achieved using JavaScript or should I be looking somewhere else?

Any Ideas would be greatly appreciated!

Prolific

3:26 pm on Aug 5, 2005 (gmt 0)

10+ Year Member



Do a google search for "AJAX" asynchronous javascript and xml.

You can use xmlhttp to send/receive data without page reloads. Its what google maps and M$ virtual earth use. Also take a look at start.com/3/ to see a good example of xmlhttp without page reloads.

hatman

6:25 pm on Aug 5, 2005 (gmt 0)

10+ Year Member



This is excactly what I was looking for! Thanks Prolific - Awesome! I feel like I have just seen the future.
Here is an interesting link to Wikipedia about AJAX in case anyone else is interested.
wikipedia [en.wikipedia.org]