0

I have a functional inline editing script on client side, however I'd like to add a button like <input type="button" value="edit here"> when someone clicks the button it should be able to select the value just like my hover selector works and produce the form

In short I want to remove the hover status selector to the click button selector.

Check out the code to understand more:

<div id="pesa"><p>PERSONAL INFORMATION</p>
    <ul>
        EMAIL:<li class="editable"><?php echo $email;?></li><input type="button" value="edit here">
        NAME:<li class="editable"><?php echo $name;?></li><input type="button" value="edit here">
        TELLPHONE:<li class="editable"><?php echo $tel;?></li>
        COUNTRY:<li class="editable"><?php echo $country;?></li>
        CITY:<li class="editable"><?php echo $city;?></li>
    </ul>
</div>  

Thank you.ok sorry i wass having trouble ith puting code tags here isthe js

$(document).ready(function() 
{
var oldText, newText;
$(".editable").hover(
    function()
    {
        $(this).addClass("editHover");
    }, 
    function()
    {
        $(this).removeClass("editHover");
    }
);

$(".editable").bind("dblclick", replaceHTML);


$(".btnSave").live("click", 
                function()
                {
                    newText = $(this).siblings("form")
                                     .children(".editBox")
                                     .val().replace(/"/g, "&quot;");

                    $(this).parent()
                           .html(newText)
                           .removeClass("noPad")
                           .bind("dblclick", replaceHTML);
                }
                ); 

$(".btnDiscard").live("click", 
                function()
                {
                    $(this).parent()
                           .html(oldText)
                           .removeClass("noPad")
                           .bind("dblclick", replaceHTML);
                }
                ); 

function replaceHTML()
                {
                    oldText = $(this).html()
                                     .replace(/"/g, "&quot;");
                    $(this).addClass("noPad")
                           .html("")
                           .html("<form><input type=\"text\" class=\"editBox\" value=\"" + oldText + "\" /> </form><a href=\"#\" class=\"btnSave\">Save changes</a> <a href=\"#\" class=\"btnDiscard\">Discard changes</a>")
                           .unbind('dblclick', replaceHTML);

                }
   }
 ); 

and the css

     #pesa a{
color: #000;
     }

    #pesa a:hover{
color: #;
     }


    #pesa a:hover{
text-decoration: none;
    }

    h1{
font-size: 30px;
padding: 0;
margin: 0;
    }

    h2{
font-size: 20px;
    }


    .editHover{
background-color: #E8F3FF;
   }

     .editBox{
width: 326px;
min-height: 20px;
padding: 10px 15px;
background-color: #fff;
border: 2px solid #E8F3FF;
    }

    #pesa ul{
list-style: none;
    }

    #pesa li{
width: 330px;
min-height: 20px;
padding: 10px 15px;
margin: 5px;
    }

   li.noPad{
padding: 0;
width: 360px;
   }

   #pesa form{
width: 100%;
  }

.btnSave, .btnCancel{
padding: 6px 30px 6px 75px;
}

.block{
float: left;
margin: 20px 0;
}
Jimmy Obonyo Abor
  • 7,335
  • 10
  • 43
  • 71

2 Answers2

0
function replaceHTML()
{
    $(this).removeClass('editHover'); 
}

Or use toggleClass() if you're using the same method for adding as well as removing the inline editor.

Robin Maben
  • 22,194
  • 16
  • 64
  • 99
  • thanksfor your answer...but thats not it you see the `
  • ` has a to be dblclicked to producethe formand populate the form with oldtext value however what i want is that clicking button sshould have the same effect as dblclickingthe
  • getme – Jimmy Obonyo Abor Aug 28 '12 at 12:26