Krish Patel Krish Patel - 4 months ago 26
Ajax Question

What to use instead of innerHTML in jQuery to get value?

<table border="0" cellpadding="10" cellspacing="1" id="edit">
<tr>
<div class="input-label">
<td>Name:</td>
</div>
<td><div class="input-tbox"><input type="text" name="Myname" id="names" contenteditable="true" onblur="saveToDatabse(this,'name','<?php echo $id;?>')" onclick="showEdit(this);" value="<?php echo $name; ?>"/></div></td>
</tr>

<tr>
<td>Username:</td>
<td><div class="input-tbox"><input type="text" name="myuser" id="user" contenteditable="true" onblur="saveToDatabse(this,'userName','<?php echo $id;?>')" onclick="showEdit(this);" value="<?php echo $username; ?>" /></div></td>
</tr>

<tr>
<td>Email:</td>
<td><div class="input-tbox"><input type="text" name="mail" id="email" contenteditable="true" onblur="saveToDatabse(this,'email','<?php echo $id;?>')" onclick="showEdit(this);" value="<?php echo $usermail; ?>" /></div></td>
</tr>
</table>


I have
saveToDatabase()
function at
onblur
event.
This is my function,

function saveToDatabse(editableObj,column,id){
$(editableObj).css("background","#FFF url('../images/loaderIcon.gif')no-repeat right");
$.ajax({
url:"update.php",
type:"POST",
data:'column='+column+'&editval='+editableObj.innerHTML+'&id='+id,
cache: false,
sucsess:function(data){
$(editableObj).css("background","#FDFDFD");
}
});
}


when I'm updating it set a blank value. I it's think because the use of
innerHTML
. I know
innerHTML
is not for jquery. So what can I use there for getting the value from this object of
saveToDatabse()
function?

Answer
 $.ajax({
        url:"update.php",
        type:"POST",
        data:({'column':column,'editval':editableObj.value,'id':id}),
        cache: false,        
        sucsess:function(data){
            $(editableObj).css("background","#FDFDFD");
        },
        error:function(data){
            alert(data); /*this will help to to find the error*/
        }
    });
Comments