Get value from html input field - html

How I can get the value of input with id="new_amount" and put it properly in Change amount url path. What I am trying right now is obviously not correct:
<td>
<input type="button"
onclick="location.href='${pageContext.request.contextPath}/update?id=${object.id}&?amount=${document.getElementById("new_amount").value}';"
value="Change Amount" />
</td>
Can someone please help me.
<table class=goods>
<tr>
<td>Name</td>
<td>Amount</td>
</tr>
<c:forEach var="object" items="${goods}">
<tr>
<td id="name"><c:out value="${object.name}"></c:out></td>
<td id="amount"><c:out value="${object.amount}"></c:out></td>
<td id="new_amount"><p>New amount:</p> <input type="number" id="new_amount" /></td>
<td><input type="button"
onclick="location.href='${pageContext.request.contextPath}/update?id=${object.id}&?amount=${document.getElementById("new_amount").value}';" value="Change Amount" /></td>
<td><input type="button" onclick="location.href='${pageContext.request.contextPath}/delete?id=${object.id }';" value="Delete"/></td>
</tr>
</c:forEach>
<tr>
<td><a href="${pageContext.request.contextPath }/addgoods">Add new
goods</a></td>
</tr>

I have done some static workaround (for looping) with three rows. It will be helpful to you.
Give id to table, Instead of appending the value directly I am calling function and use hidden value for your object_id. Also added class to the element to find that(ID is not good idea for repeated elements).
All you need to do is, change static values with your JSTL code.
<table id="goods">
<tr>
<th>Name</th>
<th>Amount</th>
<th>New Amount</th>
<th>Actions</th>
</tr>
<tr>
<td>test1</td>
<td>100</td>
<td><input type="number" name="new_amount" class="amount" /></td>
<td><input type="button" onclick="updateObject(this)" value="Edit" /> / <input type="button" onclick="deleteObject(this)" value="Delete"/></td>
<input type="hidden" value="1" class="goods_id" />
</tr>
<tr>
<td>test2</td>
<td>200</td>
<td><input type="number" name="new_amount" class="amount" /></td>
<td><input type="button" onclick="updateObject(this)" value="Edit" /> / <input type="button" onclick="deleteObject(this)" value="Delete"/></td>
<input type="hidden" value="2" class="goods_id" />
</tr>
<tr>
<td>test3</td>
<td>300</td>
<td><input type="number" name="new_amount" class="amount" /></td>
<td><input type="button" onclick="updateObject(this)" value="Edit" /> / <input type="button" onclick="deleteObject(this)" value="Delete" /></td>
<input type="hidden" value="3" class="goods_id" />
</tr>
</table>
Use these functions to get values of clicked row,
window.updateObject = function(object){
// Get nearest text box values based on class.
var object_id = $(object).closest('tr').find('.goods_id').val();
var amount = $(object).closest('tr').find('.amount').val();
alert("ID : "+object_id+" Amount :"+amount);
}
window.deleteObject = function(object){
var object_id = $(object).closest('tr').find('.goods_id').val();
alert("ID : "+object_id);
}
See the Demo. If you required I can explain more. Hope this helps.
Update :
In HTML,
Your actual requirement is looks like below, I have done this using JSTL
<table id="goods">
<tr>
<td>Name</td>
<td>Amount</td>
<td>New Amount</td>
<td>Actions</td>
</tr>
<c:forEach var="object" items="${goods}">
<tr>
<td><c:out value="${object.name}"></c:out></td>
<td><c:out value="${object.amount}"></c:out></td>
<td><p>New amount:</p> <input type="number" id="new_amount" class="amount" /></td>
<td><input type="button" onclick="updateObject(this)" value="Change Amount" /> /
<input type="button" onclick="deleteObject(this)" value="Delete"/></td>
<input type="hidden" value="${object.id}" class="goods_id" />
</tr>
</c:forEach>
<tr>
<td><a href="${pageContext.request.contextPath }/addgoods">Add new
goods</a></td>
</tr>
In Script,
window.updateObject = function(object){
// Get nearest text box values based on class.
var object_id = $(object).closest('tr').find('.goods_id').val();
var amount = $(object).closest('tr').find('.amount').val();
//alert("ID : "+object_id+" Amount :"+amount);
location.href='${pageContext.request.contextPath}/update?id=object_id&?amount=amount';
}
window.deleteObject = function(object){
var object_id = $(object).closest('tr').find('.goods_id').val();
//alert("ID : "+object_id);
location.href='${pageContext.request.contextPath}/delete?id=object_id';
}

Related

form.getlist() not working on htmx expanded form?

I have an order form in a flask-based app. The form starts out with a single row for the user to fill out with the name of a product, etc.
Then there is an Add Item button which sends an htmx request. It can be used to add an indefinite number of additional rows.
Here is the code:
<table class="table" >
<thead class="thead-dark">
<tr>
<th>Product Name</th>
<th>Unit</th>
<th>Quantity</th>
</tr>
</thead>
<form autocomplete="off" action="/neworder" method="POST">
<tr>
<td><input type="text" name="product" ></td>
<td><input type="text" name="unit"></td>
<td><input type="text" name="number_of_units"></td>
</tr>
<tr hx-target="this">
<td><button type="button" hx-get="/adminorder" hx-swap="outerHTML" >Add Item</button></td>
</tr>
</tbody>
</table>
<p>Order Date: <input type="text" name="date"></p>
<input type="submit">
</form>
htmx returns this:
<tr>
<td><input type="text" name="product"></td>
<td><input type="text" name="unit"></td>
<td><input type="text" name="number_of_units" ></td>
</tr>
<tr hx-target="this">
<td><button type="button" hx-get="/adminorder" hx-swap="outerHTML" >Add Item</button></td>
</tr>
As you see, all the inputs in a column have the same name.
When the form is submitted, I want to use flask request to do this:
#app.route('/neworder', methods=["POST"])
def new_order():
...
order_date = request.form.get("date")
items = request.form.getlist("product")
return f'<html>{order_date} - {items}</html>'
However, the only thing that ends up in items is what was entered into the first row...
I tried starting out with more than one row, and then things worked as expected, so it must have something to do with the part of the code returned by htmx...
I don't think this is relevant (?) but the function used by hx-get looks simply like this:
#app.route('/adminorder')
def admin_order():
return render_template('adminorder.html')
Your HTML template is invalid, you should move the form opening tag outside of the table. I've also added a missing <tbody> tag.
<form autocomplete="off" action="/neworder" method="POST">
<table class="table" >
<thead class="thead-dark">
<tr>
<th>Product Name</th>
<th>Unit</th>
<th>Quantity</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="text" name="product" ></td>
<td><input type="text" name="unit"></td>
<td><input type="text" name="number_of_units"></td>
</tr>
<tr hx-target="this">
<td><button type="button" hx-get="/adminorder" hx-swap="outerHTML" >Add Item</button></td>
</tr>
</tbody>
</table>
<p>Order Date: <input type="text" name="date"></p>
<input type="submit">
</form>

How to calculate variables which are in different lines (tr) of table in js?

Variables in below codes of js are
a= first column of table
b= second column
c= third column
d= forth column
$(document).on('keyup','input.expenses',function(){
var $row = $(this).closest('tr'),
// collect the 3 inputs in this row only
$exp = $row.find('.expenses'),
a = $exp.eq(0).val(),// first is a
b = $exp.eq(1).val(),// second is b
c = $exp.eq(2).val(),// third is c
d = $exp.eq(3).val();// fourth is d
var total = (a*c - b*c)-d;
$row.find("#toplamdisplay").val(total);
})
As it seems all variables will be calculated in the same line (same tr)
How can I use variable d (field of d) which is located in other line ?
For example
Current tags are
<tr>
<td>a</td>
<td>b</td>
<td>c</td>
<td>d</td>
</tr>
New tags I want to use are something like this
<tr>
<td>a</td>
<td>b</td>
<td>c</td>
</tr>
<tr>
<td>d</td>
</tr>
What I want is to have one payment field in last instead of having it in column. Please see below tags
<html>
<head>
<title></title>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js" /></script>
</head>
<body>
<table border="1">
<tr>
<td colspan="2">
<script>
$(document).on('keyup','input.expenses',function(){
var $row = $(this).closest('tr'),
// collect the 3 inputs in this row only
$exp = $row.find('.expenses'),
a = $exp.eq(0).val(),// first is a
b = $exp.eq(1).val(),// second is b
c = $exp.eq(2).val(),// third is c
d = $exp.eq(3).val();// fourth is d
//(B TIMES C)-(A TIMES C)
var total = (a*c - b*c)-d;
$row.find("#toplamdisplay").val(total);
$row.find('.expenses_sum').text( total)
})
$(document).on('keyup','input.expenses',function(){
$expenses_sum = $(this).parents('table').find('.expenses_sum');
$expenseTotal = $(this).parents('table').find('#expenses_sum2');
$expenseTotal.val('0');
$.each($expenses_sum,function(index,object){
if($(object).val()!='')
{
$expenseTotal.val(parseInt($expenseTotal.val())+parseInt($(object).val()));
}
})
});
$(document).on('keyup','input.expenses',function(){
$expenses_sum = $(this).parents('table').find('.expenses_sum2');
$expenseTotal = $(this).parents('table').find('#expenses_sum3');
$expenseTotal.val('0');
$.each($expenses_sum,function(index,object){
if($(object).val()!='')
{
$expenseTotal.val(parseInt($expenseTotal.val())+parseInt($(object).val()));
}
})
});
</script>
</td>
</tr>
<tr>
<th>Quantity</th>
<th>Quantity Returned</th>
<th>Unit Price</th>
<th>Total Price</th>
<th bgcolor="red">Payment</th>
</tr>
<tr>
<td><input type="number" name="" class="expenses Quantity" /></td>
<td><input type="number" name="" data-diff="true" class="expenses QuantityBack" /></td>
<td><input type="number" name="" class="expenses title UnitPrice" value="150" /></td>
<td><span class="toplamc"></span></td>
<td bgcolor="red"><input type="number" name="" data-diff="true" class="expenses paid" />
<input type="number" hidden name="" readonly id="toplamdisplay" class="expenses_sum" /></td>
</tr>
<tr>
<td><input type="number" name="" class="expenses Quantity" /></td>
<td><input type="number" name="" data-diff="true" class="expenses QuantityBack" /></td>
<td><input type="number" name="" class="expenses title UnitPrice" value="200" /></td>
<td><span class="toplamc"></span></td>
<td bgcolor="red"><input type="number" name="" data-diff="true" class="expenses paid" />
<input type="number" hidden name="" readonly id="toplamdisplay" class="expenses_sum" /></td>
</tr>
<tr>
<td rowspan="3"></td>
<td rowspan="3"></td>
<td>Current Value</td>
<td><input type="number" readonly id="expenses_sum2" class="expenses_sum2" /></td>
<td rowspan="3"></td>
</tr>
<tr>
<td>Last Value</td>
<td><input type="number" readonly class="expenses_sum2" name="" value="66" /></td>
</tr>
<tr>
<td><b>Total</b></td>
<td><input type="number" name="TotalCredit" readonly id="expenses_sum3"></td>
</tr>
<tr>
<td colspan="3"></td>
<td><font color="red">I NEED FIELD OF PAYMENT TO BE HERE</font></td>
</tr>
</table>
</body>
</html>
Please anyone can help me to edit js to work with my second logic of tags

Except Line Break in Input Text Fieldset

i have the following html to Capture some Data.
<fieldset>
<legend>Rezept hinzufügen</legend>
<form action="php_act/create.php" method="post">
<table cellspacing="0" cellpadding="0">
<tr>
<th>Rezept Name</th>
<td><input type="text" name="name" placeholder="Rezept Name" /></td>
</tr>
<tr>
<th>Kurzbeschreibung</th>
<td><input type="text" name="kurztext" placeholder="Kurzbeschreibung" class="kurztext" /></td>
</tr>
<tr>
<th>Kategorie</th>
<td><input type="text" name="Kategorie" placeholder="Kategorien - mit , trennen" /></td>
</tr>
<tr>
<th>Anforderung</th>
<td><select name="Anforderung">
<option value="einfach">einfach</option>
<option value="mittel">mittel</option>
<option value="schwer">schwer</option>
</select></td>
</tr>
<tr>
<th>Zeit / Nährwerte</th>
<td><input type="text" name="zeit" placeholder="Zeit in minuten" /></td>
<td><input type="text" name="KCAL" placeholder="KCAL" size="6"/></td>
<td><input type="text" name="KH" placeholder="KH" size="6"/></td>
<td><input type="text" name="Eiweiss" placeholder="Eiweiss" size="6"/></td>
<td><input type="text" name="Fett" placeholder="Fett" size="6" /></td>
</tr>
<tr>
<th>Portionen</th>
<td><input type="text" name="Portionen" placeholder="Portionen" /></td>
</tr>
<tr>
<th>Zutaten</th>
<td><input type="text" name="zutaten" placeholder="Zutaten" /></td>
</tr>
<tr>
<th>Zubereitung</th>
<td><input type="text" name="zubereitung" placeholder="Zubereitung" /></td>
</tr>
<tr>
<th>FotoliaID</th>
<td><input type="text" name="FotoliaID" placeholder="FotoliaID" /></td>
</tr>
<tr>
<td><button type="submit">Speichern</button></td>
<td><button type="button">zurück</button></td>
</tr>
</table>
</form>
</fieldset>
There are some Input Type Text. i need to capture line breaks within the textfields. Problem is that "Enter" submits by default the. Is it possible to change that. Enter should add a line break in the textfield and not submit the form.
Can't you use textarea instead of textbox?
In a textarea you can insert enters.
https://www.w3schools.com/tags/tag_textarea.asp

How do i submit my angular form?

I have my edit page and i would like to submit info to db once fields have been edited, it seems like something simple yet i cannot find a good example that pertains to my situation, i really don't know how to go about resolving this, this is the last part of my project. I would appreciate any suggestions Please.
This is my edit page code:
<title>
</title>
</head>
<body ng-app="app" ng-controller="decontroller" class="container">
<div id="banner" style="text-align:center; margin-left:auto; margin- right:auto; display:block;">
</div>
<h2></h2>
<h3>Personal Information:</h3>
<div id="validation-errors">
</div>
<form action="" method="post" accept-charset="utf-8" ng-submit="addEdit()">
<table class="table table-bordered">
<tbody>
<tr>
<td>ParticipantID</td>
<td>{{edit.Stlc_id}}</td>
</tr>
<tr>
<td>First Name:<br>
</td>
<td>{{edit.First_Name}}</td>
</tr>
<tr>
<td>Last Name:<br>
</td>
<td>{{edit.Last_Name}}</td>
</tr>
<tr>
<td>Address:</td>
<td><input type="text" name ="Address" ng-model="edit.Address" ></td>
</tr>
<tr>
<td>Phone:</td>
<td><input size="20" name ="phone" ng-model="edit.Phone_Number" ></td>
</tr>
<tr>
<td>Assistive Devices:</td>
<td><input name ="AssistiveDevices" ng-model="edit.Assistive_Devices" ></td>
</tr>
<tr>
<td>Lanyard Code</td>
<td>
<input name ="Lanyard_Status" ng-model="edit.Lanyard_Status" /> </td>
</tr>
<tr>
<td>Comments</td>
<td>
<textarea cols="100" name="comments" ng-model="edit.Comments">.</textarea>
</td>
</tr>
<tr>
<td>Disenrolled</td>
<td><input name="disenrolled" ng-model="edit.Disenrolled" ></td>
</tr>
<tr>
<td>Deceased</td>
<td><input name="deceased" ng-model="edit.Deceased" ></td>
</tr>
</tbody>
</table>
</form>
<h3>Days in Center<br></h3>
<table class="table table-bordered">
<tbody>
<tr>
<td>Monday</td>
<td>Tuesday</td>
<td>Wednesday</td>
<td>Thursday</td>
<td>Friday</td>
</tr>
<tr>
<td><input name="Attendance_Monday" ng-model="edit.Attendance_Monday" ></td>
<td><input name="Attendance_Tuesday" ng-model="edit.Attendance_Tuesday" ></td>
<td><input name="Attendance_Wednesday" ng-model="edit.Attendance_Wednesday" ></td>
<td><input name="Attendance_Thursday" ng-model="edit.Attendance_Thursday" ></td>
<td><input name="Attendance_Friday" ng-model="edit.Attendance_Friday" > </td>
</tr>
</tbody>
</table>
<h3>Transportation Types</h3>
<table class="table table-bordered">
<tr>
<td>Type of Transportation</td>
<td>Approved For</td>
<td>Comments</td>
</tr>
<tr>
<td width="300px">Wheel Chair Van</td>
<td><input name="WheelChair_Van" ng-model="edit.WheelChair_Van"></td>
<td><textarea cols="100" name="WheelChair_Van comments" ng-model="edit.Comments" ></textarea></td>
</tr>
<tr>
<td width="300px">Transit Van 240</td>
<td><input name="TransitVan_240" ng-model="edit.TransitVan_240"></td>
<td><textarea cols="100" name="TransitVan_240 comments" ng-model="edit.Comments" ></textarea></td>
</tr>
<tr>
<td width="300px">Transit Van 360</td>
<td><input name="TransitVan_360" ng-model="edit.TransitVan_360"></td>
<td><textarea cols="100" name="TransitVan_360 comments" ng- model="edit.Comments"></textarea></td>
</tr>
<tr>
<td width="300px">Subaru Impreza</td>
<td><input name="Subaru_Impreza" ng-model="edit.Subaru_Impreza"></td>
<td><textarea cols="100" name="Subaru_Impreza comments" ng- model="edit.Comments"></textarea></td>
</tr>
</table>
<h3>Pick up and Drop Off Times</h3>
<br>
<table class="table table-bordered">
<tr>
<td width="300px">Pick Up Time:</td><td><input type="text" name="Pick_Up_Time" value=""></td>
</tr>
<tr>
<td width="300px">Drop off Time</td><td><input type="text" name="Drop_Off_Time" value=""></td>
</tr>
</table>
<br>
<h3>Personal Care Hours Pick Up/Drop Off</h3>
<table class="table table-bordered">
<tbody>
<tr>
<td>Monday</td>
<td>Tuesday</td>
<td>Wednesday</td>
<td>Thursday</td>
<td>Friday</td>
<td>Saturday</td>
<td>Sunday</td>
</tr>
<tr>
<td><input type="text" name="Monday_Pick_Up" ng-model="edit.Monday_Pick_Up" placeholder="Pick Up Time"></td>
<td><input type="text" name="Tuesday_Pick_Up" ng-model="edit.Tuesday_Pick_Up" placeholder="Pick Up Time"></td>
<td><input type="text" name="Wednesday_Pick_Up" ng-model="edit.Wednesday_Pick_Up" placeholder="Pick Up Time"></td>
<td><input type="text" name="Thursday_Pick_Up" ng-model="edit.Thursday_Pick_Up" placeholder="Pick Up Time"></td>
<td><input type="text" name="Friday_Pick_Up" ng-model="edit.Friday_Pick_Up" placeholder="Pick Up Time"></td>
<td><input type="text" name="Saturday_Pick_Up" ng-model="edit.Saturday_Pick_Up" placeholder="Pick Up Time"></td>
<td><input type="text" name="Sunday_Pick_Up" ng-model="edit.Sunday_Pick_Up" placeholder="Pick Up Time"></td>
</tr>
<tr>
<td><input type="text" name="Monday_Drop_Off" ng-model="edit.Monday_Drop_Off" placeholder="Drop Off Time"></td>
<td><input type="text" name="Tuesday_Drop_Off" ng-model="edit.Tuesday_Drop_Off" placeholder="Drop Off Time"></td>
<td><input type="text" name="Wednesday_Drop_Off" ng-model="edit.Wednesday_Drop_Off" placeholder="Drop Off Time"></td>
<td><input type="text" name="Thursday_Drop_Off" ng-model="edit.Thursday_Drop_Off" placeholder="Drop Off Time"></td>
<td><input type="text" name="Friday_Drop_Off" ng-model="edit.Friday_Drop_Off" placeholder="Drop Off Time"></td>
<td><input type="text" name="Saturday_Drop_Off" ng-model="edit.Saturday_Drop_Off" placeholder="Drop Off Time"></td>
<td><input type="text" name="Sunday_Drop_Off" ng-model="edit.Sunday_Drop_Off" placeholder="Drop Off Time"></td>
</tr>
</tbody>
</table>
<input type="submit" name="submit" ng-click="saveEdit()" />
</form>
<pre>{{edit | json}}</pre>
<a href="http://localhost:8080/stlc/index.php/transport/list_show_data/transport_vi ew">
<button type="button" class="btn btn-primary">Back</button>
</a>
<script src="http://code.jquery.com/jquery-3.1.1.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"> </script>
<script type="text/javascript">
var app = angular.module('app',[]);
app.controller('decontroller', function($scope,$http){
$scope.edit=<?php echo json_encode($aggregate_data_view);?>;
$scope.saveEdit = function(){
console.log("hey i'm submitting!");
console.log($scope.edit);
$http.post('?php echo site_url("index.php/transport/saveData")?>', $scope.edit).
success(function(data){console.log(":)") }).
error(function(data){
console.log(":(")
});
};
});
</script>
</body>
</html>
Here is my Controller:
public function saveData()
{
}
it is empty now cause i really don't know what to do,nothing has worked.
In my page I have three button. First two create random AVL data on the page
the second one save that data to the db
HTML:
<button data-ng-click="createAvl()">Create Avl</button>
<button data-ng-click="create1000Avl()">Create 1000 Avl</button>
<button data-ng-click="saveAvl()">Save Avl</button>
ngController:
app.controller("myCtrl", function ($scope, $http) {
$scope.avl = []; --here is where i save the avl
$scope.avl.push({
'tracker_avl_id': getRandomArbitrary(0, 1000000, 1),
'plate_num': getRandomArbitrary(0, 10000, 1),
'x_lat': getRandomArbitrary(-69, -66, 0),
'y_long': getRandomArbitrary(8, 10, 0),
'azimuth': getRandomArbitrary(0, 359, 1),
'engine_status': engine,
'gps_fix': gps_fix,
'event_time': getRandomDate()
});
$scope.saveAvl = function () {
$scope.ResponseDetails = 'Working...'; -- some variables to show progress
$scope.startDate = getDate();
$scope.startTime = new Date().getTime();
$scope.timeEllapsed = null;
-- use $.param jQuery function to serialize data from JSON
var data = $.param({
avl_list: $scope.avl
});
var config = {
headers: {
'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;'
}
}
-- send the data to my webservice
$http.post('/AvlApi/putTrackerAVL', data, config)
.success(function (data, status, headers, config) {
var end = new Date().getTime() - $scope.startTime;
$scope.timeEllapsed = 'milliseconds passed: ' + end;
$scope.ResponseDetails = data;
})
.error(function (data, status, header, config) {
$scope.ResponseDetails = "Data: " + data +
"<hr />status: " + status +
"<hr />headers: " + header +
"<hr />config: " + config;
});
};
My Webservice is in IIS using C#
[HttpPost]
public JsonResult putTrackerAVL(List<avl> avl_list)
{
try
{
avl_list.ForEach(car => db.avl.Add(car));
db.SaveChanges();
}
catch (Exception ex)
{
return Json(new { status = "Fail", message = ex.InnerException });
}
return Json(new { status = "Success" });
}

HTML table multiple forms Ajax submit

I have a table with multiple rows and multiple forms and I am trying to send each form to my PHP script.
When not using Ajax all the forms update correctly. However with Ajax I cannot get the PHP script to work. How can I get the Ajax to work?
On HTML part, I have multiple rows which belong to one form (In the example below all the rows belong to one form and I have multiple of these). I did read that a FORM tag cannot be under TR tag and even know when I look at the code it looks pretty ugly, but I am not sure how else I can build the table.
Ajax
$(document).ready(function(){
// click on button submit
$("#submit").on('click', function(){
// send ajax
$.ajax({
url: 'post.php', // url where to submit the request
type : "POST", // type of action POST || GET
dataType : 'json', // data type
data : $(this).serialize(), // post data || get data
})
});
});
HTML
<tbody>
<tr>
<form id="form1" method="POST" action=""></form>
<input type="hidden" name="ID" value="">
<td rowspan="6">bls</td>
<td rowspan="6">qasachin.dwxmp41#mailinator.com</td>
<td>Records</td>
<td>10</td>
<td>1</td>
<td><input type="text" size="1" value="" name="Records"></td>
<td>Contact</td>
<td></td>
<td><input type="text" size="1" value="" name="Contact"></td>
<td rowspan="6"><textarea id="usrform" name="comment">Tadas</textarea></td>
<td><button type="submit" id="submit" value="approve" class="btn btn-warning">Approve</button></td>
</tr>
<tr>
<td>Centers</td>
<td>15</td>
<td>1</td>
<td><input type="text" size="1" value="" name="Centers"></td>
<td>Company</td>
<td>Tadas</td>
<td><input type="text" size="1" value="" name="Company"></td>
</tr>
<tr>
<td>Duration</td>
<td>10</td>
<td>0</td>
<td><input type="text" size="1" value="" name="Duration"></td>
<td>Address</td>
<td></td>
<td><input type="text" size="1" value="" name="Address"></td>
<td><button type="submit" formaction="" class="btn btn-info btn-xs btn-block">Invoice</button></td>
</tr>
<tr>
<td>GCP</td>
<td>0</td>
<td></td>
<td><input type="text" size="1" value="" name="GCP"></td>
<td>Zip</td><td>10</td><td><input type="text" size="1" value="" name="Zip"></td>
<td><a target="_blank" href="mailto:qasachin.dwxmp41#mailinator.com" class="btn btn-success>Email</a></td>
</tr>
<tr>
<td>RAND</td>
<td>0</td>
<td>0</td>
<td><input type="text" size="1" value="" name="RAND"></td>
<td>City</td>
<td>Amsterdam</td>
<td><input type="text" size="1" value="" name="City"></td>
</tr>
<tr>
<td>Price</td>
<td>€39</td>
<td>€18</td>
<td><input type="text" size="1" value="" name="Price"></td>
<td>Departm</td>
<td>IT</td>
<td><input type="text" size="1" value="" name="Departm"></td>
</tr>
You have invalid HTML markup.
Only td and th elements are allowed to be child elements of tr.
And you are immediately closing your form tag. Which means you don't have any fields inside your form.
You should put your whole table inside your form.
<form id="form1" method="POST" action="">
<input type="hidden" name="ID" value="">
<table>
<tbody>
<tr>
<td rowspan="6">bls</td>
<td rowspan="6">qasachin.dwxmp41#mailinator.com</td>
<td>Records</td>
<td>10</td>
<td>1</td>
<td><input type="text" size="1" value="" name="Records"></td>
<td>Contact</td>
<td></td>
<td><input type="text" size="1" value="" name="Contact"></td>
<td rowspan="6"><textarea id="usrform" name="comment">Tadas</textarea></td>
<td><button type="submit" id="submit" value="approve" class="btn btn-warning">Approve</button></td>
</tr>
<tr>
<td>Centers</td>
<td>15</td>
<td>1</td>
<td><input type="text" size="1" value="" name="Centers"></td>
<td>Company</td>
<td>Tadas</td>
<td><input type="text" size="1" value="" name="Company"></td>
</tr>
<tr>
<td>Duration</td>
<td>10</td>
<td>0</td>
<td><input type="text" size="1" value="" name="Duration"></td>
<td>Address</td>
<td></td>
<td><input type="text" size="1" value="" name="Address"></td>
<td><button type="submit" formaction="" class="btn btn-info btn-xs btn-block">Invoice</button></td>
</tr>
<tr>
<td>GCP</td>
<td>0</td>
<td></td>
<td><input type="text" size="1" value="" name="GCP"></td>
<td>Zip</td><td>10</td><td><input type="text" size="1" value="" name="Zip"></td>
<td><a target="_blank" href="mailto:qasachin.dwxmp41#mailinator.com" class="btn btn-success>Email</a></td>
</tr>
<tr>
<td>RAND</td>
<td>0</td>
<td>0</td>
<td><input type="text" size="1" value="" name="RAND"></td>
<td>City</td>
<td>Amsterdam</td>
<td><input type="text" size="1" value="" name="City"></td>
</tr>
<tr>
<td>Price</td>
<td>€39</td>
<td>€18</td>
<td><input type="text" size="1" value="" name="Price"></td>
<td>Departm</td>
<td>IT</td>
<td><input type="text" size="1" value="" name="Departm"></td>
</tr>
</tbody>
</table>
</form>
You also need to handle the submit event on your form or your page will be reloaded.
You can do that by calling e.preventDefault() inside the handler.
$(function(){
// click on button submit
$("#form1").on("submit", function(e){
e.preventDefault(); // prevent page reload on submit
// send ajax
$.ajax({
url: 'post.php', // url where to submit the request
type : "POST", // type of action POST || GET
dataType : 'json', // data type
data : $(this).serialize(), // post data || get data
})
});
});