jQuery - Get the value of the closest text box
<p>How to get the value of the closest text-box, while clicking the button? Actually, I'm creating a table with five columns, where two columns will have dynamically generated text-boxes and each of it will have separate id. The last column will contain save button. When the button is clicked, those values should be saved in the db. I've tried like this:</p>

<pre><code>    var a = 0;
    var b = 0;
    var table;
    //var c = 0;
    jQuery(document).ready(function(){
        jQuery.ajaxSetup({ cache: false });     

        table = jQuery("#table_billing").dataTable({
                "sAjaxSource": "includes/inc-billing2-db.php?mode=billing_dataTable",
                "bDestroy": true,
                "bPaginate": false,
                "bInfo": false,
                "bFilter": false,
                "bSort": false,
                "aoColumnDefs": [
                    {
                        "aTargets": [2],
                        "mRender": function(data, type, row) {
                            return '&lt;input type="text" class="form-control invoice_number" name="invoice_number" id="invoice_number_'+ a +'" placeholder="Invoice Number" required="required" onblur="getvalue(this)"&gt;';
                            var x = row[3];
                            var y = row[4];

                        }
                    },
                    {
                        "aTargets": [3],
                        "mRender": function(data, type, row) {
                            return '&lt;input type="text" class="form-control date" name="invoice_date" id="invoice_date_'+ b +'" placeholder="Invoice Date" required="required"&gt;';
                        }
                    },
                    {
                        "aTargets": [4],
                        "mRender": function(data, type, row) {
                            return '&lt;input type="button" class="btn-group btn-default btn-sm save" value="Save" name="save_bill" id="save_bill" onclick="jQuery(this).save(' + row[3] + ', ' + row[4] + ', ' + jQuery("#invoice_number_0").val() + ');"&gt;';
                        }
                    }
                ],
                "fnCreatedRow": function(nRow, aData, iDisplayIndex, iDisplayIndexFull){
                    a = a + 1;
                    b = b + 1;
                    //c = c + 1;
                }
            });

            jQuery.fn.save = function (id, contract_invoice_request_id, value){
                alert(id);
                alert(contract_invoice_request_id);
                alert(value);

            if(jQuery("#invoice_number").val() == ''){
                alert("Please enter the invoice number!");
                jQuery("#invoice_number").focus();
            }
            if(jQuery("#invoice_date").val() == ''){
                alert("Please select the invoice date!");
                jQuery("#invoice_date").focus();
            }

            jQuery.ajax({
                type: "POST",
                url: "includes/inc-billing-db.php?mode=save_billing",
                data:{ "contract_id": aData[2],
                    "invoice_number": jQuery("#save_bill").val(),
                    "invoice_date": jQuery("#invoice_date").val()
                    },
                success: function(data, text){
                        jQuery.msgbox_success(data.message);
                        jQuery("#billing_"+this.id).closest('tr').remove();
                        jQuery("#date_"+this.id).closest('tr').remove();

                }       
            });
    }
}); 
function getvalue(txt){
                alert(txt.id);
                var tr = $("#"+ txt.id).closest('tr');
                console.log(tr);
                var data = table.row(tr).data();
                alert(data);
                data.invoice_number = txt.val();
            }
</code></pre>

<p>But, I get the error as table.row is not a function. What is wrong and what should I do? </p>