Whenever a user adds a new row to the dynamic table to input customer information, I require the data to be submitted in JSON format upon clicking the submit button.
HTML
<table class="table table-bordered table-hover" id="driver">
<thead>
<tr>
<th class="text-center text-info">
#
</th>
<th class="text-center text-info">
first name
</th>
<th class="text-center text-info">
last name
</th>
<th class="text-center text-info">
mobile num
</th>
<th class="text-center text-info">
email id
</th>
</tr>
</thead>
<tbody>
<tr id='addr0'>
<td>
1
</td>
<td>
<input type="text" name='firstname' placeholder='first name' class="form-control"/>
</td>
<td>
<input type="text" name='lastname' placeholder='last name' class="form-control"/>
</td>
<td>
<input type="text" name='mobile' placeholder='mobile number' class="form-control"/>
</td>
<td>
<input type="text" name='email' placeholder='email' class="form-control"/>
</td>
</tr>
<tr id='addr1'></tr>
</tbody>
</table>
I am looking to have the JSON data structured in key and value pairs. Any suggestions on how we can achieve this?
[
{
"first name": "ashok",
"last name": "kumar",
"mobile num": 45,
"email id": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bec6c7c6fed9d3dfd7d290ddd1d3">[email protected]</a>"
},
{
"first name": "arun",
"last name": "kumar",
"mobile num": 789,
"email id": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a0cbd5cde0c1d38ec3cfcd">[email protected]</a>"
}
]