PDA

View Full Version : String Replace Problem :-)



snowysweb
01-09-2009, 09:25 AM
could anyone tell me if im on the right lines with this. i know nothing of ajax so please bear with.



string = obj.innerHTML.replace('<img scr="', '');
string2 = string2.replace('" height="100" width="100" >', '');


it doesnt work but anyone put me in the right direction?

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

rnd me
01-09-2009, 01:14 PM
string = obj.innerHTML.replace('<img scr="', '');
string2 = string.replace('" height="100" width="100" >', '');

snowysweb
01-09-2009, 02:28 PM
with that this is the code and it doesn't work. any ideas? snowysblog (http://81.106.168.84/new_idea2/)

(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.)



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="', '');
string2 = string.replace('" height="100" width="100" >', '');
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);
}

snowysweb
01-09-2009, 02:30 PM
actualy it does work just doesnt do anything.

snowysweb
01-09-2009, 02:31 PM
if that makes sense

snowysweb
01-09-2009, 02:33 PM
see if you click on the box where there is an image, it is supposed to display the

tags. but it does not.