Datatable column search with HTML Textbox - ajax

I am trying to enable column search with datatables. I set u Search textboxes with HTML :
<div class="col-lg-3 mb-lg-0 mb-6">
<label>Id:</label>
<input type="text" name="textbox[]" class="form-control datatable-input" placeholder="E.g: 1" data-col-index="0" />
</div>
<div class="col-lg-3 mb-lg-0 mb-6">
<label>Amount:</label>
<input type="text" name="textbox[]" class="form-control datatable-input" placeholder="E.g: 4500" data-col-index="1" />
</div>
And here is my search Ajax :
function addSearchControl(json) {
$("#searchTable thead");
$("#searchTable").each(function (index) {
var searchControl = $('input[name="textbox[]"]');
searchControl.on('keyup', function () {
var indexDataTable = searchControl.index( this );
alert( this.value + ', ' + indexDataTable );
empTable.column(indexDataTable).search(searchControl.val()).draw();
});
});
}
But only first textbox is working and when I type something on the second textbox I get the index which is 1 but cannot search on column 1
This is for Dropdown search I get the value but it doesnt search the table just renders table again :
$('#dropDownMenuKategorie :selected').text();
$("#dropDownMenuKategorie").on('change', function() {
var textSelected = $('#dropDownMenuKategorie option:selected').val();
alert(textSelected);
empTable.column(9).search(textSelected).draw();
});

Maybe you can change the column().search() method like this
empTable.column(indexDataTable).search(this.value).draw();
Sample:
<div class="col-lg-3 mb-lg-0 mb-6">
<label>Name:</label>
<input type="text" name="textbox[]" class="form-control datatable-input" placeholder="E.g: 1" data-col-index="0" />
</div>
<div class="col-lg-3 mb-lg-0 mb-6">
<label>Position:</label>
<input type="text" name="textbox[]" class="form-control datatable-input" placeholder="E.g: 4500" data-col-index="1" />
</div>
<div class="col-lg-12">
<table id="searchTable" class="display" style="width:100%">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</thead>
<tbody>
<tr>
<td>Tiger Nixon</td>
<td>System Architect</td>
<td>Edinburgh</td>
<td>61</td>
<td>2011/04/25</td>
<td>$320,800</td>
</tr>
<tr>
<td>Garrett Winters</td>
<td>Accountant</td>
<td>Tokyo</td>
<td>63</td>
<td>2011/07/25</td>
<td>$170,750</td>
</tr>
<tr>
<td>Ashton Cox</td>
<td>Junior Technical Author</td>
<td>San Francisco</td>
<td>66</td>
<td>2009/01/12</td>
<td>$86,000</td>
</tr>
</tbody>
</table>
</div>
#section scripts{
<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script src="https://cdn.datatables.net/1.10.22/js/jquery.dataTables.min.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.22/css/jquery.dataTables.min.css" />
<script>
$(document).ready(function () {
var empTable = $("#searchTable").DataTable();
$("#searchTable").each(function (index) {
var searchControl = $('input[name="textbox[]"]');
searchControl.on('keyup', function () {
var indexDataTable = searchControl.index(this);
//alert(this.value + ', ' + indexDataTable);
empTable.column(indexDataTable).search(this.value).draw();
});
});
})
</script>
}
Result:

Related

Laravel vue js 3 need to edit single record from table

I have this following:
<div class="modal-body" >
<form v-for="lead in editleads" id="" class="form-horizontal validate-form">
<input v-model="editl" type="text" class="form-control my-2 py-2" :placeholder="lead">
</form>
</div>
<table class="table table-hover align-middle mb-0">
<thead class="">
<tr>
<th><input type="checkbox" class="form-check-input" v-model="selectAll" title="Select All"></th>
<th v-for="(header, index) in visibleHeaders" :key="index" scope="col">
{{ header }}
</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr v-show="leads.length" v-for="(column, index) in visibileColumn" :key="index">
<td>
<input type="checkbox" class="form-check-input" v-model="selected" :value="column.id" />
</td>
<td v-for="atr in column">
{{atr}}
</td>
<td>
<button #click="editLead(column.id)" type="button" class="btn btn-sm btn-secondary" data-mdb-toggle="modal" data-mdb-target="#editLeadModal" >
<i class="fa-solid fa-pen-to-square"></i>
</button>
</td>
</tr>
<tr v-show="!leads.length">
<td colspan="12" class="text-center">Sorry :( No data found.</td>
</tr>
</tbody>
</table>
data() {
reurn {
headers: [],
leads: [],
...
}
},
editLead(id) {
axios.get('/leads/'+id+'/edit')
.then(response => {
this.editleads = response.data.leads
})
},
I want to edit each table record one by one. I mean to edit single record, but the problem is i return an array object from backend and i dont know how to edit each input. If i click now on form all input filled with same value. can someone help with this

Multiple Table search using one dropdown filter in datatable

I am using laravel and data table here I am using 2 data tables on the same page. Now I need to filter both at the same time using the dropdown. The dropdown filter is located outside my table. one table content revenue another one content Expense for the same account number.
I also want to subtract the total value. is like the 1st value came from 1st table total value, and 2nd value came from 2nd table then its subtract. is it possible?
Here Is My Code
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css" >
<link href="https://cdn.datatables.net/1.11.1/css/jquery.dataTables.min.css" rel="stylesheet">
<link href="https://cdn.datatables.net/datetime/1.1.0/css/dataTables.dateTime.min.css" rel="stylesheet">
<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script src="https://cdn.datatables.net/1.11.0/js/jquery.dataTables.js"></script>
<title>JS Bin</title>
</head>
<body>
<div class="card">
<h4 class="text-center mt-3 mb-3"><u>Filter</u></h4>
<div class="card-body">
<div>
<div class="row">
<div class="col-sm-4">
<div class="form-group row">
<label for="staticEmail" class="col-sm-4 col-form-label text-dark">Account Number</label>
<div class="col-sm-8">
<div id="account_number"></div>
</div>
</div>
</div>
<div class="col-sm-4">
<div class="form-group row">
<label for="staticEmail" class="col-sm-4 col-form-label text-dark">From</label>
<div class="col-sm-8">
<input type="text" class="form-control" id="min" name="min" placeholder="mm/dd/yyyy">
</div>
</div>
</div>
<div class="col-sm-4">
<div class="form-group row">
<label for="staticEmail" class="col-sm-4 col-form-label text-dark">To</label>
<div class="col-sm-8">
<input type="text" class="form-control" id="max" name="max" placeholder="mm/dd/yyyy">
</div>
</div>
</div>
</div>
</div>
<div id="buttons"></div>
</div>
</div>
<div class="card">
<h4 class="text-center mt-3 mb-3"><u>Bank Statement</u></h4>
<p class="text-center" id="account_number1"></p>
<div class="card-body">
<div class="table-responsive">
<table class=" table table-borderless " style="min-width: 845px">
<thead>
<tr>
<th>Account Number</th>
<th>BAnk Name</th>
<th>Date</th>
<th>Expenses</th>
<th class="text-center">Amount</th>
</tr>
</thead>
<tbody>
<!-- #foreach (App\Models\BankTransaction::where('type','debit')->get() as $item) -->
<tr>
<td>35302111502</td>
<td>ABC Bank</td>
<td>2021-09-07</td>
<td>Withdraw</td>
<td class="text-center">10000</td>
</tr>
<!-- #endforeach -->
<tr>
<td>35302111502</td>
<td>ABC Bank</td>
<td>2021-09-07</td>
<td>Online Payment</td>
<td class="text-center">10000</td>
</tr>
<tr>
<td>35302111502</td>
<td>ABC Bank</td>
<td>2021-09-07</td>
<td>Online Payment</td>
<td class="text-center">10000</td>
</tr>
<tr>
<td>54-0211-15145</td>
<td>ANC Bank</td>
<td>2021-09-05</td>
<td>Card Bill</td>
<td class="text-center">6000</td>
</tr>
</tbody>
<tfoot>
<tr>
<th>Account Number</th>
<th>BAnk Name</th>
<th>Date</th>
<th>Expenses</th>
<th class="text-center">Amount</th>
</tr>
</tfoot>
</table>
<table class=" table table-borderless " style="min-width: 845px">
<thead>
<tr>
<th>Account Number</th>
<th>BAnk Name</th>
<th>Date</th>
<th>Revenues</th>
<th class="text-center">Amount</th>
</tr>
</thead>
<tbody>
<!-- #foreach (App\Models\BankTransaction::where('type','credit')->get() as $item) -->
<tr>
<td>35302111502</td>
<td>ABC Bank</td>
<td>2021-09-06</td>
<td>Account Open</td>
<td class="text-center">1000</td>
</tr>
<!-- #endforeach -->
<tr>
<td>35302111502</td>
<td>ABC Bank</td>
<td>2021-09-06</td>
<td>Diposit</td>
<td class="text-center">10000</td>
</tr>
<tr>
<td>35302111502</td>
<td>ABC Bank</td>
<td>2021-09-07</td>
<td>Balance Transfer</td>
<td class="text-center">10000</td>
</tr>
<tr>
<td>54-0211-15145</td>
<td>ANC Bank</td>
<td>2021-09-01</td>
<td>Account Opening</td>
<td class="text-center">1000</td>
</tr>
<tr>
<td>54-0211-15145</td>
<td>ANC Bank</td>
<td>2021-09-03</td>
<td>Diposit</td>
<td class="text-center">3000</td>
</tr>
<tr>
<td>54-0211-15145</td>
<td>ANC Bank</td>
<td>2021-09-05</td>
<td>Online Earn</td>
<td class="text-center">6000</td>
</tr>
</tbody>
<tfoot>
<tr>
<th>Account Number</th>
<th>BAnk Name</th>
<th>Date</th>
<th class="text-dark"><h4>Total Revenues</h4></th>
<th class="text-dark text-center h4"></th>
</tr>
</tfoot>
</table>
</div>
</div>
</div>
</body>
<script>
$(document).ready(function() {
//Date Filter Start
var minDate, maxDate;
$.fn.dataTable.ext.search.push(
function( settings, data, dataIndex ) {
var min = minDate.val();
var max = maxDate.val();
var date = new Date( data[1] );
if (
( min === null && max === null ) ||
( min === null && date <= max ) ||
( min <= date && max === null ) ||
( min <= date && date <= max )
) {
return true;
}
return false;
}
);
minDate = new DateTime($('#min'), {
format: 'MMMM Do YYYY'
});
maxDate = new DateTime($('#max'), {
format: 'MMMM Do YYYY'
});
var editor;
var table= $('table.table-borderless').DataTable({
"dom":'t',
"columnDefs": [
{
"targets": [ 1 ],
"visible": false,
"searchable": true
},
{
"targets": [ 0 ],
"visible": false,
"searchable": true
},
],
"footerCallback": function ( row, data, start, end, display ) {
var api = this.api();
// Remove the formatting to get integer data for summation
var intVal = function ( i ) {
return typeof i === 'string' ?
i.replace(/[\$,]/g, '')*1 :
typeof i === 'number' ?
i : 0;
};
amount = api
.column( 3, { search: "applied" } )
.data()
.reduce( function (a, b) {
return intVal(a) + intVal(b);
}, 0 );
// Update footer
$( api.column( 3 ).footer() ).html(
amount
);
},
initComplete: function() {
//Drop Down Account Number
var column = this.api().column(0);
var select = $('<select class="form-control" ><option value="">All Account</option></select>')
.appendTo($('#account_number').empty())
.on('change', function() {
var val = $.fn.dataTable.util.escapeRegex(
$(this).val()
);
column.search(val ? '^' + val + '$' : '', true, false).draw();
document.getElementById("account_number1").innerHTML = val;
//console.log(column);
});
column.data().unique().sort().each(function(d, j) {
select.append('<option value="' + d + '">' + d + '</option>');
});
}
});
//Date Filter
$('#min, #max').on('change', function () {
table.draw();
});
});
</script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-/bQdsTh/da6pkI1MST/rWKFNjaCP5gBSY4sEBT38Q/9RBh9AH40zEOg7Hlq2THRZ" crossorigin="anonymous"></script>
<script src="https://cdn.datatables.net/1.11.0/js/jquery.dataTables.js"></script>
<script src="https://cdn.datatables.net/plug-ins/1.11.0/api/sum().js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>
<script src="https://cdn.datatables.net/datetime/1.1.0/js/dataTables.dateTime.min.js"></script>
</html>

How to set table cells values independently with using x-for alpine.js?

I am trying to make a table includes table in every row, and nested x-for is used with alpine.js.With clicking the button located in the lower right corner of the table, new row is added and all cells in the rows have the same value. I couldn't set the rows' values independently. Could you please help?
Thanks in advance for your help,
Cem
function handler() {
return {
fields1: [],
fields: [],
rows: [],
addRate() {
this.fields1.push({
value1: '',
value2: '',
value3: '',
rType: '',
typeA: '',
value4: '',
typeBDateFrom: '',
typeBDateTo: ''
});
},
listField() {
this.fields.splice(0);
this.fields1.splice(0);
this.rows.push({
id: this.id++
});
this.fields1.push({
value1: '',
value2: '',
value3: '',
rType: '',
typeA: '',
value4: '',
typeBDateFrom: '',
typeBDateTo: ''
});
this.fields.push({
value5: '3',
value6: '20',
value7: 'DC',
value8: '40',
value9: '523',
value10: '654',
value11: 'TEST',
value12: 'true',
value13: 'Class1',
value14: '5656',
value15: 'TRM78799',
id:'1'
});
},
}
};
function setDecimal(event) {
this.value = parseFloat(this.value).toFixed(3);
};
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<div class="container col-md-10 offset-md-1">
<div class="row" x-data="handler()" x-init="listField()">
<div class="col">
<table class="table align-items-center table-sm" style="text-align: center;">
<tr>
<template x-for="(row, index) in rows" :key="index">
<p>
<table class="table align-items-center table-sm table-bordered" style="text-align: center;">
<tbody>
<template x-for="(field1, index) in fields1" :key="index">
<tr class="table-success">
<td style="width:100px;"><b>Type</b></td>
<td style="width:100px;">
<select x-model="field1.rType" class="custom-select" name="rType"
id="rType" required>
<option selected>---</option>
<option value="Type A">Type A</option>
<option value="Type B">Type B</option>
</select>
</td>
<td x-show="field1.rType==='Type A'" style="width:120px;">
<b>Type A Name</b>
</td>
<td x-show="field1.rType==='Type A'">
<input x-model="field1.typeA" type="text" class="form-control"
name="typeA" id="typeA">
</td>
<td x-show="field1.rType==='Type A'" style="width:150px;">
<b>Value4</b>
</td>
<td x-show="field1.rType==='Type A'">
<input x-model="field1.value4" type="text" class="form-control"
name="value4" id="value4">
</td>
<td x-show="field1.rType==='Type B'" style="width:120px;">
<b>From</b>
</td>
<td x-show="field1.rType==='Type B'">
<input x-model="field1.typeBDateFrom" type="Type B" class="form-control"
name="typeBDateFrom" id="typeBDateFrom">
</td>
<td x-show="field1.rType==='Type B'" style="width:150px;">
<b>To</b>
</td>
<td x-show="field1.rType==='Type B'">
<input x-model="field1.typeBDateTo" type="Type B" class="form-control"
name="typeBDateTo" id="typeBDateTo">
</td>
</tr>
</template>
</tbody>
</table>
</p>
<p>
<table class="table align-items-center table-sm table-bordered" style="text-align: center;">
<thead class="thead-dark">
<tr>
<th>No</th>
<th style="width:20px;">Value5</th>
<th style="width:80px;">Value6</th>
<th style="width:150px;">Value7</th>
<th style="width:120px;">Value8</th>
<th style="width:120px;">Value9</th>
<th style="width:130px;">Value11</th>
<th style="width:180px;">Value12</th>
<th style="width:180px;">Value1</th>
<th style="width:180px;">Value2</th>
<th style="width:180px;">Value3</th>
</tr>
</thead>
<tbody>
<template x-for="(field, index) in fields" :key="index">
<tr>
<td x-text="index + 1"></td>
<td x-text="field.value5"></td>
<td x-text="field.value6"></td>
<td>
<p x-text="field.value7"></p>
<p
x-show="field.value7==='RFR' | field.value7==='RFRHC'">
<span x-text="field.value8"></span><span>
℃</span>
</p>
</td>
<td x-text="field.value9"></td>
<td x-text="field.value10"></td>
<td x-text="field.value11"></td>
<td x-show="field.value12">
<p>
<label><b>Value13 </b><span x-text="field.value13"></span></label>
</p>
<p>
<label><b>Value14 </b><span x-text="field.value14"></span></label>
</p>
</td>
<td x-show="!field.value12">
<p>
</p>
</td>
<td class="table-success">
<input x-model="field.value1" type="number" class="form-control"
onchange="setDecimal" min="0" max="10000000" name="value1"
id="value1" step="0.001" value="0.000" required>
</td>
<td class="table-success">
<select x-model="field.value2" class="custom-select" name="value2"
id="value2" required>
<option selected>---</option>
<option value="USD">USD</option>
<option value="EUR">EUR</option>
</select>
</td>
<td class="table-success">
<input x-model="field.value3" type="text" class="form-control"
name="value3" id="value3">
</td>
</tr>
</template>
</tbody>
</table>
</p>
</template>
</tr>
<tr>
<td colspan="12" class="text-right"><button type="button" class="btn btn-info"
#click="listField()">+ Add Row</button></td>
</tr>
</table>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script src="https://cdn.jsdelivr.net/gh/alpinejs/alpine#v2.8.2/dist/alpine.min.js" defer></script>

Spring Boot doesnt return template in Post Mapping

I hope some of you have an idea about this. I'm still new to Spring but till this point I could figured out every problem myself. I'm using also Thymeleaf for the templates.
In the Controller the function for #GetMapping works as intended, but the #PostMapping function doesnt return the template which I specified in the return parameter and so the browser shows the wrong page.
The #PostMapping function gets triggered by the ajax statement in the html script.
I get no errors or warnings on server side as well as on client side. So I have no idea were the spot the mistake.
Hope some of you can spot the mistake. Thanks in advance anyway.
Controller:
#Controller
public class SpringController {
#RequestMapping(value="/tank", method = RequestMethod.GET)
public String loadData(Model model){
Tankstelle[] data = TankerAPI.getTankData(lat, lng, 5, sort, type);
model.addAllAttributes(convertdata("name", data));
model.addAllAttributes(convertdata("dist", data));
model.addAllAttributes(convertdata("price", data));
return "home";
}
#RequestMapping(value = "/tank", method = RequestMethod.POST)
public String getChangedData(#RequestBody JSONObject incomingjson) {
lat = Float.parseFloat(incomingjson.get("lat").toString());
lng = Float.parseFloat(incomingjson.get("lng").toString());
BigDecimal biglat = new BigDecimal(lat).setScale(3, RoundingMode.HALF_UP);
BigDecimal biglng = new BigDecimal(lng).setScale(3, RoundingMode.HALF_UP);
lat = biglat.floatValue();
lng = biglng.floatValue();
sort = "price"; //for seeing a difference
System.out.println(incomingjson.get("lat")+" "+incomingjson.get("lng"));
return "test"; //here it should return the template "test" but it return "home"
}
home.html:
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org/">
<head>
<meta charset="UTF-8"/>
<title>guenstigertanken.de</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<style>...
</style>
</head>
<body onload="getLocation()">
<div class="ueberschriftbox"></div>
<h2 class="header">guenstigertanken.de</h2>
<h2 class="subheader">Wir finden die günstigsten Spritpreise für Sie</h2>
<div class="backrounding">
<div class="steuerelementebox"></div>
<div class="steuerelementespritsorteueberschrift">
<h2>Spritsorte</h2>
<label class="container1">Super E5
<input type="radio" id="E5" name="radio1" onclick="autoSubmit()">
<span class="checkmark1"></span>
</label>
<label class="container1">Super E10
<input type="radio" id="E10" name="radio1" onclick="autoSubmit()">
<span class="checkmark1"></span>
</label>
<label class="container1">Diesel
<input type="radio" id="Diesel" name="radio1" onclick="autoSubmit()">
<span class="checkmark1"></span>
</label>
</div>
<div class="steuerelementesortierennachueberschrift">
<h2>Sortieren nach</h2>
<label class="container2">Preis aufsteigend
<input type="radio" checked="checked" name="radio2" onclick="autoSubmit()">
<span class="checkmark2"></span>
</label>
<label class="container2">Preis absteigend
<input type="radio" name="radio2" onclick="autoSubmit()">
<span class="checkmark2"></span>
</label>
<label class="container2">Distanz aufsteigend
<input type="radio" name="radio2" onclick="autoSubmit()">
<span class="checkmark2"></span>
</label> <label class="container2">Distanz absteigend
<input type="radio" name="radio2" onclick="autoSubmit()">
<span class="checkmark2"></span>
</label>
<label class="container2" id="alph">Name alphabetisch
<input type="radio" name="radio2" onclick="autoSubmit()">
<span class="checkmark2"></span>
</label>
</div>
<div class="buttonsbox"></div>
<div class="tabellenbox"></div>
<div class="ueberuns">
<p>Über uns</p>
</div>
<div class="agb">
<p>AGB</p>
</div>
<div class="datenschutz">
<p>Datenschutz</p>
</div>
<div class="impressum">
<p>Impressum</p>
</div>
<div class="left show">
<table id="datatable">
<thead>
<tr> <th>Name</th> <th>Entfernung</th> <th>Preis</th> <th>Favorit</th> </tr>
</thead>
<tbody>
<tr> <td th:text="${name1}">AGIP</td> <td th:text="${dist1}">7km</td> <td th:text="${price1}">1,20€</td> <td><input type="checkbox"></td> </tr>
<tr> <td th:text="${name2}">Aral</td> <td th:text="${dist2}">12km</td> <td th:text="${price2}">1,23€</td> <td><input type="checkbox"></td> </tr>
<tr> <td th:text="${name3}">Esso</td> <td th:text="${dist3}">2km</td> <td th:text="${price3}">1,25€</td> <td><input type="checkbox"></td> </tr>
<tr> <td th:text="${name4}">Esso</td> <td th:text="${dist4}">10km</td> <td th:text="${price4}">1,25€</td> <td><input type="checkbox"></td> </tr>
<tr> <td th:text="${name5}">Esso</td> <td th:text="${dist5}">5km</td> <td th:text="${price5}">1,25€</td> <td><input type="checkbox"></td> </tr>
<tr> <td th:text="${name6}">BP</td> <td th:text="${dist6}">13km</td> <td th:text="${price6}">1,35€</td> <td><input type="checkbox"></td> </tr>
<tr> <td th:text="${name7}">BP</td> <td th:text="${dist7}">13km</td> <td th:text="${price7}">1,35€</td> <td><input type="checkbox"></td> </tr>
<tr> <td th:text="${name8}">BP</td> <td th:text="${dist8}">13km</td> <td th:text="${price8}">1,35€</td> <td><input type="checkbox"></td> </tr>
</tbody>
</table>
</div>
</div>
<a class="cssbuttonfavoriten" href="test.html">Favoriten></a>
<a class="cssbuttonleaderboard" href="test.html">Leaderboard></a>
<a class="cssbuttonstatistiken" href="test.html">Statistiken></a>
<script>
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
}
}
function showPosition(position) {
var posdata = '{"lat":"'+position.coords.latitude+'","lng":"'+position.coords.longitude+'","typeselect":"'+type+'"}';
$.ajax({
type: 'post',
url: '/tank',
data: JSON.stringify(posdata),
contentType: "application/json; charset=utf-8",
traditional: true,
success: function(posdata) {
//alert("ajax success: refresh page to sort after price[prob current setting]")
},
error: function(){
alert("ajax error")
}
});
}
</script>
</body>
</html>
When you make any request through ajax you just receive corresponding response in your callback function:
success: function(posdata) {
//alert("ajax success: refresh page to sort after price[prob current setting]")
},
So browser will not show you a new template page. Your page is in "postdata" response

Dynamically inserted textbox values to be stored in a variable

<tr style="background: #D0CDCD;">
<td colspan='2'>
<input type="text" name="mytext1[]">
</td>
<td></td>
<td colspan='2' style="text-align:right;">
<input type="text" name="mytext2[]" id="txt1" onkeyup="sum();">
</td>
</tr>
This is my html code to add dynamic textboxes.
JS Script is follows
<script type="text/javascript">
$(document).ready(function() {
var max_fields= 3;
var x = 1;
$('a').click(function() {
if(x < max_fields){
x++;
$('#myTable #row').append('<tr class="child"><td class="child" colspan="2"><input type="text" name="mytext1[]"></td><td></td><td colspan="2" style="text-align:right;"><input type="text" name="mytext2[]"></td></tr>');
}
});
});
</script>
My problem is that I need to store the dynamically added textbox values to a variable so that I can perform some mathematical operations in that. I don't know how to achieve this. Please help me.
I got the result. I make use of javascript and jQuery
<tr style="background: #D0CDCD;">
<td colspan='2'><input type="text" name="mytext1[]"></td>
<td></td>
<td colspan='2' style="text-align:right;">
<input type="text" class="value_field" name="mytext2[]" >
</td>
</tr>
Function to append
<script type="text/javascript">
$(document).ready(function() {
$('a').click(function() {
$('#myTable #row').append('<tr class="child"><td class="child" colspan="2"><input type="text" name="mytext1[]"></td><td></td><td colspan="2" style="text-align:right;"><input type="text" name="mytext2[]" class="value_field"></td></tr>');
$("input.value_field").blur(function(){
check_value();
});
});
});
$("input.value_field").blur(function(){
check_value();
});

Resources