Javascript EditInPlace ?

Discussion in 'JavaScript' started by reptile1903, Mar 27, 2009.

  1. #1
    Hello,

    I tried to edit in place with javascript as first but it didn't work.(Then i will import ajax). All codes here (basic).

    
    function Wrt(a,b) {
    	document.getElementById(b).onclick = Edit(b);
    	document.getElementById(b).innerHTML = a;
    }
    function Edit(idd) {
    	var Now = document.getElementById(idd).innerHTML;
    	document.getElementById(idd).onclick = function() { void(0) };
    	var txt = '<textarea id="text_box" onblur="return Wrt(this.value,'+ idd +')">'+Now+'</textarea>';
    	document.getElementById(idd).innerHTML = txt;
    	document.getElementById('text_box').focus();
    }
    
    
    Code (markup):
    
    <a href="#" id="1" onclick="Edit(this.id)">Text 1</a>
    <a href="#" id="2" onclick="Edit(this.id)">Text 2</a>
    
    Code (markup):
    It works but when I tried second time(edit that place) , it is not working.
     
    reptile1903, Mar 27, 2009 IP
  2. reptile1903

    reptile1903 Member

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #2
    Hello,

    I solved this problem :)

    I changed

    document.getElementById(b).onclick = Edit(b);

    with

    document.getElementById(b).onclick = function() { Edit(this.id); }
     
    reptile1903, Mar 29, 2009 IP