views:

177

answers:

3
function areaMe(area){
    var barea = $('#barea').val();
    if(barea.indexOf(area)!=-1){
     alert ("..." + barea + "..." + area + "...");
     barea.replace(area, "cu"); // remove
     alert ("..." + barea + "..." + area + "...");
    }else{
     barea+=area+' '; // inlcui
    }
    $('#barea').val(barea);
}
+12  A: 
barea = barea.replace(area, "cu")

You need to assign it since String.prototype.replace isn't a mutator method.

meder
+6  A: 

You need to assign the replaced value back to your variable:

barea = barea.replace(area, "cu");
Gumbo
A: 

barea = barea.replace(area, "cu")

WisdomFusion