views:

48

answers:

1

Hello. I have a profile.php, where each user in the community have their profile. Now i want to do something smart out of the editing, so i wish to do so when you click on a field it turns to a input and then you can edit it the field.. (example: www.azzyh.dk, click on "Click ME") Anyways,

I know how to do this already, heres a script:

<script language="JavaScript">
function createObject() {  
var request_type;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
request_type = new ActiveXObject("Microsoft.XMLHTTP");
}else{
request_type = new XMLHttpRequest();
}
return request_type;
}

var http = createObject();
function myEditable(e, act) {
    if (act == 'click') {
        // lav indholdet af span om til et input felt og sæt et onblue event på den
        e.innerHTML = '<input type="text" value="'+e.innerHTML+'" onblur="myEditable(this, \'edit\')" />';

        // fjern span onclick eventen
        e.onclick = null;

    } else if (act == 'edit') {
    var nocache = 0;
        // hent span elementet igen
        var parentElement = e.parentNode;

        // Opdater span teksten, e.value er den nye værdi
        parentElement.innerHTML = e.value;
        nocache = Math.random();
        var tekstny= e.value;
            http.open('get', 'editsave.php?tekstny='+tekstny+'&nocache = '+nocache);
http.onreadystatechange = insertReply;
http.send(null);
        // placer onclick eventen igen på span elementet
        (function(e){
                e.onclick = function()
                {
                    myEditable(e, 'click');
                };
            })(parentElement);


    }
    function insertReply() {
if(http.readyState == 4){
var response = http.responseText;
// else if login is ok show a message: "Site added+ site URL".
document.getElementById('insert_response').innerHTML = ''+response;
}
} 

}
</script>
<p>
    <h1><div align="center"><span onclick="myEditable(this, 'click');"><?=$row["felt"]; ?></span></h1></div>
</p>    <div id="insert_response">Respons: </div>

And this works good.

But what i now want to is to add more fields to edit, and then make a submit button appear when you starts to edit a field.

How should i do this?

So if i have 5 fields it would output:

http.open('get', 'editsave.php?field1='+field1+'&field2='+field2+'&field3='+field3+'&field4='+field4+'&field5='+field5+'&nocache = '+nocache);

Thank you stackoverflow community!

+1  A: 

See this please. Instructions are there on how to implement that. Thanks

And other option.

Sarfraz