Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to pass value of input textbox and its id to javascript function so it makes post request via ajax?
    primarykey
    data
    text
    <p>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!</p> <p>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</p> <pre><code> $table3.="&lt;tr&gt;"; $table3.="&lt;td&gt;" . $row['ID'] ."(".$totalRows. ")&lt;/td&gt;"; $table3.="&lt;td bgcolor=\"#FF0000\"&gt;&lt;input type=\"text\" id =\"". $row['ID'] ."\" name=\"". $row['ID'] ."\" value=\"edit\"&gt;&lt;button onclick='setNewValue(\"".$row['ID']."\")'&gt;Edit this Row&lt;/button&gt;&lt;/td&gt;"; $table3.="&lt;td&gt;" . $row['imgPURL'] . "&lt;/td&gt;"; $table3.="&lt;td&gt;" . $row['imgUrl'] . "&lt;/td&gt;"; $table3.="&lt;td&gt;".$line."&lt;/td&gt;"; echo "&lt;/tr&gt;"; </code></pre> <p>javascript :</p> <pre><code>&lt;script&gt; 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")&gt;=0) { //remote the edit button button.hide(); } else { //change caption of edit button to try again button.text("some text"); } }) } &lt;/javascript&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload