Log in

View Full Version : click, edit and save text script without refreshing page?



acctman
08-17-2007, 06:49 PM
i'm looking for a script that will allow the users to click and edit text then save without reloading the page.

example:

Sample user text. (when user click on the text it turns into an editable field that they can change, then maybe a save button appears too or something to save changes to the database)

djr33
08-17-2007, 09:20 PM
There's an easy way to do this without even needing Ajax (a style of coding which would allow javascript to transmit data to the server).

Use an onChange event on the textbox, or onChange with onKeydown on a certain interval (after about 5 seconds of no change would be good), and then save that data to the server by submitting through an image.
Change the src for the image to ...img.php?val=[the text will go here], using Javascript. Have that PHP script output an image (this isn't too hard) which will say "updated" (and could even give the current time), or could be small/invisible, if you want.

When the page loads, just get the text from the file and load it into the textbox, with PHP. Easy.
<?php echo file_get_contents('my.txt'); ?>

The PHP image script will display the image in the end, but also save the data from the $_GET['val'] variable.
$f = fopen('text.txt','w+');
fwrite($f,$_GET['val']);
fclose($f);

tech_support (another user here) and I had a working example of this a while ago on his server. I think he probably still has a copy. I'll ask him to post that.

RickDawson
07-02-2008, 12:14 AM
I know this is an old threadw...
Do you still have this?

I'm looking for something like this.

techietim
07-02-2008, 12:59 AM
Sorry for feeding an old thread.

I have attached a script that might work for you.

RickDawson
07-02-2008, 01:22 AM
Thanks :)
I'll look at it when I get home after working in the morning.

magicyte
07-07-2008, 06:34 PM
Simple. Using any AJAX would be simple, along with XML, PHP, possibly JavaScript. But there should be some sort of server involved.

-magicyte

Beverleyh
07-21-2009, 07:19 PM
I found this download and its very useful but I would like to adapt it further and need some help.

I've edited the save.php file with a code snippet to work with php4 but I dont really know that much about php to adapt the script to work on an editable area within the index.php page itself rather than reading and changing content in an external contents.txt file.

So, I'd like to edit an editable div in index.php and save it to index.php (not the external contents.txt file)
It also needs to be compatiable with php4

Can anybody offer any coding assistance please?

Thanks

Beverleyh
07-22-2009, 09:26 AM
Ok - I've done some more Googling and come across this code which might be an alternative to the editor429_v2.zip download above. (The edito429 script is my first choice but the code below also does a similar job and I'm sure could be adapted to my needs)

Code is here: http://codingforums.com/showthread.php?p=768811

Example editable page is here: http://edit.awardspace.co.uk/

The problem is at the moment, when you go into edit mode, you can see and edit all the html tags - what I would really like is for the edit page to just show the content as defined within an editable area rather than the whole web page structure.

I have no idea how to adapt the code to target and pluck out the contents of a named div for example so if somebody could offer some assistance, I would be very grateful.

Thanks