javascript - In Jquery take a different values from single text box id -
i using data table in jquery. passed 1 input type text box , passed single id. data table take multiple text box. enter values manually , pass controller. want take 1 or more text box values array..
the following image exact view of data table. have marked red color in 1 place. 3 text boxes in same id different values. how bind that?
function updateamount() {debugger; var id = ""; var count = 0; $("input:checkbox[name=che]:checked").each(function () { if (count == 0) { id = $(this).val(); var amount= $('#amount').val(); } else { id += "," + $(this).val(); amount+="," + $(this).val(); // if give getting first text box value only. } count = count + 1; }); if (count == 0) { alert("please select atleast 1 record update"); return false; }
really stuck find out solution... want text box values ?
so, fundamental rule must not have duplicate ids. hence, use classes. so, in example, replace ids of text boxes classes, like:
<input class="amount" type="text" />
then, try below code.
function updateamount() { debugger; var amount = []; $("input:checkbox[name=che]:checked").each(function () { var $row = $(this).closest("tr"); var inputval = $row.find(".amount").val(); amount.push(inputval); }); console.log (amount); // array of values console.log (amount.join(", ")); // comma separated string of values if (!amount.length) { alert("please select atleast 1 record update"); return false; } }
see if works , add details code does.
Comments
Post a Comment