i got some editable textbox inside html table cells! Each textbox got a summit button. I want send value of textbox and id of textbox to javascript function so it makes ajax post request to php script and edit mysql row!
My problem is that i dont know how to pass textbox value and its corresponding id to javascript and change textbox button on response of ajax.Does my buttons need unique ids as well ? could any one show me how this can done.Thanks
$table3.="<tr>";
$table3.="<td>" . $row['ID'] ."(".$totalRows. ")</td>";
$table3.="<td bgcolor=\"#FF0000\"><input type=\"text\" id =\"". $row['ID'] ."\" name=\"". $row['ID'] ."\" value=\"edit\"><button onclick='setNewValue(\"".$row['ID']."\")'>Edit this Row</button></td>";
$table3.="<td>" . $row['imgPURL'] . "</td>";
$table3.="<td>" . $row['imgUrl'] . "</td>";
$table3.="<td>".$line."</td>"; echo "</tr>";
javascript :
<script>
function setNewValue(a,b) {
var button = $(event.target); // get button here
var text = $("#"+a);
var textboxvalue = text.val();
//alert("inputId:"+a+"\nuInputValue:"+b);
var url = "./edit.php";
$.post(url, {
"method": "post",
"rowId": a,
"rowValue": textboxvalue,
}, function(data)
{
var ajaxResponse = data;
//alert("success"+ajaxResponse);
if(ajaxResponse.indexOf("SuccessEdit")>=0)
{
//remote the edit button
button.hide();
}
else
{
//change caption of edit button to try again
button.text("some text");
}
})
}
</javascript>