Results 1 to 3 of 3

Thread: how to update to db the changed data from this javascript?

  1. #1
    Join Date
    Aug 2005
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default how to update to db the changed data from this javascript?

    Hi,


    The code:
    Code:
    Event.observe(window, 'load', init, false);
    
    function init(){
    	var max = 50;
    	for (i = 1; i <= max; i++){
    
    	makeEditable('item_'+i);}
    }
    
    function makeEditable(id){
    	Event.observe(id, 'dblclick', function(){edit($(id))}, false);
    	Event.observe(id, 'mouseover', function(){showAsEditable($(id))}, false);
    	Event.observe(id, 'mouseout', function(){showAsEditable($(id), true)}, false);
    }
    
    function edit(obj){
    	Element.hide(obj);
    	
    	var textarea = '<div id="'+obj.id+'_editor" align="right"><input id="'+obj.id+'_edit" name="'+obj.id+'" type="text" size="22" maxlength="22" value="'+obj.innerHTML+'">';
    	var button	 = '<input id="'+obj.id+'_save" type="button" value="ok" /><input id="'+obj.id+'_cancel" type="button" value="cancel" /></div>';
    	
    	new Insertion.After(obj, textarea+button);	
    		
    	Event.observe(obj.id+'_save', 'click', function(){saveChanges(obj)}, false);
    	Event.observe(obj.id+'_cancel', 'click', function(){cleanUp(obj)}, false);
    	document.getElementById(obj.id+'_edit').focus();
    }
    
    function showAsEditable(obj, clear){
    	if (!clear){
    		Element.addClassName(obj, 'editable');
    	}else{
    		Element.removeClassName(obj, 'editable');
    	}
    }
    
    function saveChanges(obj){
    	
    	var new_content	=  escape($F(obj.id+'_edit'));
    
    	obj.innerHTML	= "Saving...";
    	cleanUp(obj, true);
    
    	var success	= function(t){editComplete(t, obj);}
    	var failure	= function(t){editFailed(t, obj);}
    
      	var url = 'edit.php';
    	var pars = 'id='+obj.id+'&content='+new_content;
    	var myAjax = new Ajax.Request(url, {method:'post', postBody:pars, onSuccess:success, onFailure:failure});
    
    }
    
    function cleanUp(obj, keepEditable){
    	Element.remove(obj.id+'_editor');
    	Element.show(obj);
    	if (!keepEditable) showAsEditable(obj, true);
    }
    
    function editComplete(t, obj){
    	obj.innerHTML	= t.responseText;
    	showAsEditable(obj, true);
    }
    
    function editFailed(t, obj){
    	obj.innerHTML	= 'Sorry, the update failed.';
    	cleanUp(obj);
    }
    I can save the data to a databse using var url = 'edit.php';, but what to put in edit.php? Cause nothing gets saved now...

    Thx
    Last edited by Null; 03-04-2007 at 12:48 PM.

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    What's in your edit.php now?
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Aug 2005
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    my edit.php is now:
    Code:
    <?php
        ==Databaseconnection goes here==
        $id = $_POST['id'];
        $content = $_POST['content'];
        echo stripslashes(htmlentities($content));
     ?>
    This will return the edited tekst in $content.
    Tried several database updates, but non ever worked, so this is my edit.php as cleasn as I can give it...

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •