Hi. I have worked on a script, that will makes so when you click on a text it changes to a input field and a submit buttom. In the input field you can change the text, and the submit button to "apply" the new changes. Now i cant get it to work, when you press the submit button. When you click the submit button it just changes the input field to "Edit".. Here's my coding:
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+'" />' +
'<input type="submit" value="Edit" name="Submit"' +
'onclick="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;
}
}
}
It works without the input button, but i wish it to work with the button.
Edit: Summary including jsbin: Go to: http://jsbin.com/ofave . As you see herem when you click on "Field1" it changes to a inputfield with a submit button with "edit". Now what i wants to do is when you click on the submit button "edit" it should update the span text(to what you changed) & go back to normal text. It does do this, WITHOUT the submit button, but i want the script to work with the submit button i added into the script..