jQuery addClass example

Change class name on click in jQuery

by Павел KLON

HTML

<form action="#" id="form1">
<table>
  <tr>
    <td>
      <input type="hidden" value="12">
      Иван Иванович
    </td>
    <td>
      <input type="text" value="США">
    </td>
    <td>
      <input type="text" value="2019">
    </td>
    <td>
      <input type="text" value="путешествие">
    </td>
    <td>
      <input type="text" value="какой то текст">
    </td>
    <td>
      <input type="text" value="12">
    </td>
  </tr>
  <tr>
    <td>
      <input type="hidden" value="12">
      Иван Иванович
    </td>
    <td>
      <input type="text" value="Бали">
    </td>
    <td>
      <input type="text" value="2018">
    </td>
    <td>
      <input type="text" value="путешествие">
    </td>
    <td>
      <input type="text" value="какой то текст2">
    </td>
    <td>
      <input type="text" value="8">
    </td>
  </tr>
</table>
<input type="submit" value="ok">
</form>

<div id="res"></div>

JavaScript

$('#form1').submit(function (e) {
    
       function asdd() {
    const result = [];
    $('#form1').find('tr').each((i, tr) => {
        const row = [];
        const inputs = $(tr).find('input').each((i, input) => {
            row.push(`'${input.value}'`)
        });
        result.push(`(${row.join(',')})`)
    });

    return result.join(',');
}

$('#res').html(asdd());

 e.preventDefault();
});