Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Sep 2008
    Posts
    280
    Thanks
    25
    Thanked 9 Times in 9 Posts

    String Replace Problem :-)

    could anyone tell me if im on the right lines with this. i know nothing of ajax so please bear with.

    Code:
    string = obj.innerHTML.replace('<img scr="', '[img]');
    string2 = string2.replace('" height="100" width="100" >', '[/img]');
    it doesnt work but anyone put me in the right direction?

    (i apologise for the lame subject in the previous post)

  • #2
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,273
    Thanks
    10
    Thanked 581 Times in 562 Posts
    Code:
    string = obj.innerHTML.replace('<img scr="', '[img]');
    string2 = string.replace('" height="100" width="100" >', '[/img]');
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #3
    Regular Coder
    Join Date
    Sep 2008
    Posts
    280
    Thanks
    25
    Thanked 9 Times in 9 Posts
    with that this is the code and it doesn't work. any ideas? snowysblog

    (if you click on the link at the bottom of the page "Is this your blog" and use usr:snowy pas:multiscans

    and then click on any of the text you can see it just calapses the boxes.)

    Code:
    Event.observe(window, 'load', init, false);
    
    function init(){
    	makeEditable('index_1');
    	makeEditable('index_2');
    	makeEditable('index_3');
    	makeEditable('index_4');
    	makeEditable('index_5');
    	makeEditable('index_6');
    	makeEditable('index_7');
    	makeEditable('index_1_TaBlE');
    	makeEditable('index_2_TaBlE');
    	makeEditable('index_3_TaBlE');
    	makeEditable('index_4_TaBlE');
    	makeEditable('index_5_TaBlE');
    	makeEditable('index_6_TaBlE');
    	makeEditable('index_7_TaBlE');
    }
    
    function makeEditable(id){
    	Event.observe(id, 'click', 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);
    
    	string = obj.innerHTML.replace('<img scr="', '[img]');
    	string2 = string.replace('" height="100" width="100" >', '[/img]');
    	var textarea = '<div id="'+obj.id+'_editor"><textarea id="'+obj.id+'_edit" name="'+obj.id+'" rows="4" cols="60">'+string2L+'</textarea>';
    	var button	 = '<div><input id="'+obj.id+'_save" type="button" value="SAVE" /> OR <input id="'+obj.id+'_cancel" type="button" value="CANCEL" /></div></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);
    	
    }
    
    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);
    }

  • #4
    Regular Coder
    Join Date
    Sep 2008
    Posts
    280
    Thanks
    25
    Thanked 9 Times in 9 Posts
    actualy it does work just doesnt do anything.

  • #5
    Regular Coder
    Join Date
    Sep 2008
    Posts
    280
    Thanks
    25
    Thanked 9 Times in 9 Posts
    if that makes sense

  • #6
    Regular Coder
    Join Date
    Sep 2008
    Posts
    280
    Thanks
    25
    Thanked 9 Times in 9 Posts
    see if you click on the box where there is an image, it is supposed to display the
    Code:
    [img][/img]
    tags. but it does not.


  •  

    Posting Permissions

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