Send ID of changed row in table (html to JS)

Orik00

I have 7 row and i need to use my function only for row which was edited. How can i send id? or maybe there are more easy way? I tried to send number of row id onChange="setprice(this.value,18,5)" last one is ID of row, but on split int+ string I can not detetct it as ID . For example: var idofrow = ('setvalue'+row); $("#idofrow").html("");. #idofrow does not work

function setprice(val, ay, row) {
  var rowid_ilk = event.target.getAttribute('id');
  $("#rowid_ilk").html("");
  var total = Math.round((((({{ price_without_symbol }  } - val) / ay) * ({{      kredittable.kredit_faiz / 100 }})) + (({{ price_without_symbol }} - val) / ay)));
  var rowset = 'setvalue' + row;
  alert(rowset);
  rowset.innerHTML += total;
}
<table class="table table-striped" id="tablebrd">
  <thead>
    <tr>
      <th scope="col">{{ text_kredit_mesac }}</th>
      <th scope="col" style="width: 28%">{{ text_min_vznos }}</th>
      <th scope="col">{{ text_mes_plata }}</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>3 {{ text_kredit_mesaca }}</td>
      <td><input type="number" name="ilkoden" id="ilkoden1" value="{{ kredittable.kredit_min_ilkin  }}" onChange="setprice(this.value,3,1)" /></td>
      <td>
        <div id="setvalue1"></div>
      </td>
    </tr>
    <tr>
      <td>6 {{ text_kredit_mesaca }}</td>
      <td><input type="number" name="ilkoden" id="ilkoden2" value="{{ kredittable.kredit_min_ilkin  }}" onChange="setprice(this.value,6,2)" /></td>
      <td>
        <div id="setvalue2"></div>
      </td>
    </tr>

    <tr>
      <td>9 {{ text_kredit_mesaca }}</td>
      <td><input type="number" name="ilkoden" id="ilkoden3" value="{{ kredittable.kredit_min_ilkin  }}" onChange="setprice(this.value,9,3)" /></td>
      <td>
        <div id="setvalue3"></div>
      </td>
    </tr>

    <tr>
      <td>12 {{ text_kredit_mesaca }}</td>
      <td><input type="number" name="ilkoden" id="ilkoden4" value="{{ kredittable.kredit_min_ilkin  }}" onChange="setprice(this.value,12,4)" /></td>
      <td>
        <div id="setvalue4"></div>
      </td>
    </tr>

    <tr>
      <td>18 {{ text_kredit_mesaca }}</td>
      <td><input type="number" name="ilkoden" id="ilkoden5" value="{{ kredittable.kredit_min_ilkin  }}" onChange="setprice(this.value,18,5)" /></td>
      <td>
        <div id="setvalue5"></div>
      </td>
    </tr>

    <tr>
      <td>24 {{ text_kredit_mesaca }}</td>
      <td><input type="number" name="ilkoden" id="ilkoden6" value="{{ kredittable.kredit_min_ilkin  }}" onChange="setprice(this.value,24,6)" /></td>
      <td>
        <div id="setvalue6"></div>
      </td>
    </tr>

    <tr>
      <td>36 {{ text_kredit_mesaca }}</td>
      <td><input type="number" name="ilkoden" id="ilkoden7" value="{{ kredittable.kredit_min_ilkin  }}" onChange="setprice(this.value,36,7)" /></td>
      <td>
        <div id="setvalue7"></div>
      </td>
    </tr>
  </tbody>
</table>

Ivan

You can access the id of your changed element by accessing the target property of the event: event.target:

event.target is a reference to the object that dispatched the event

Then access its id name with .getAttribute. And remove the first seven letters of the id name to get the element's number with the method .substr.

event.target.getAttribute('id').substr(7)

Here's a quick demo:

const fn = function() {
  console.log(event.target.getAttribute('id').substr(7))
}
<div id="ilkoden11" onclick="fn()">This is item 11</div>


If you want to select the id of an element on the same level, you will need to do some navigating inside the HTML tree, the following selector will do that:

const div = event.target.closest('tr').querySelector('div').id;
                              ↑                  ↑
                        parent <tr>      find <div> child

Here is an example:

const setprice = function() {
  const target = event.target.id;
  const value = event.target.value;
  const div = event.target.closest('tr').querySelector('div').id;
  console.log(target, value, div)
}
<table>
<tr>
  <td><input id="ilkoden2" onkeyup="setprice()" /></td>
  <td>
    <div id="setvalue2"></div>
  </td>
</tr>
</table>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Get the table row id on click (HTML+JS)

From Dev

JS Append Row in HTML Table

From Dev

JS Append Row in HTML Table

From Dev

Adding id to html table row in JavaScript

From Dev

Javascript Add Row to HTML Table & Increment ID

From Dev

Get row id of dynamic table in html

From Dev

Sum of a Column with Distinct Row id in HTML TABLE with jquery or JS Example is below

From Dev

Select a row from html table and send values onclick of a button

From Dev

Select a row (highlight) from html table and send values onclick of a button

From Dev

Select a row (highlight) from html table and send values onclick of a button

From Java

Table add row, edit row, save row, delete row Using HTML, CSS, JS

From Dev

In Html Table is it possible to get the id of elements situated in another row?

From Dev

Hide first row of html table 2 having no class and no id attributes

From Dev

In Html Table is it possible to get the id of elements situated in another row?

From Dev

How to get table row by id and then change it's value / html

From Dev

Send a particular row of a table to a function

From Dev

SQL query not updating table when row is changed

From Dev

How to know a row of a table has changed?

From Dev

Disable table row on checkbox changed event

From Dev

Html table with fixed header column and row without JS

From Dev

hide with js an HTML table row <tr> so that it takes up no space

From Dev

Filter Table Row in Html

From Dev

Selecting a row in a html table

From Dev

HTML Row table selection

From Dev

Filter Table Row in Html

From Dev

HTML Row table selection

From Dev

aligning the table row in HTML

From Dev

Send entire html table to tcpdf

From Dev

Table "jumps" when url is changed, angular js

Related Related

  1. 1

    Get the table row id on click (HTML+JS)

  2. 2

    JS Append Row in HTML Table

  3. 3

    JS Append Row in HTML Table

  4. 4

    Adding id to html table row in JavaScript

  5. 5

    Javascript Add Row to HTML Table & Increment ID

  6. 6

    Get row id of dynamic table in html

  7. 7

    Sum of a Column with Distinct Row id in HTML TABLE with jquery or JS Example is below

  8. 8

    Select a row from html table and send values onclick of a button

  9. 9

    Select a row (highlight) from html table and send values onclick of a button

  10. 10

    Select a row (highlight) from html table and send values onclick of a button

  11. 11

    Table add row, edit row, save row, delete row Using HTML, CSS, JS

  12. 12

    In Html Table is it possible to get the id of elements situated in another row?

  13. 13

    Hide first row of html table 2 having no class and no id attributes

  14. 14

    In Html Table is it possible to get the id of elements situated in another row?

  15. 15

    How to get table row by id and then change it's value / html

  16. 16

    Send a particular row of a table to a function

  17. 17

    SQL query not updating table when row is changed

  18. 18

    How to know a row of a table has changed?

  19. 19

    Disable table row on checkbox changed event

  20. 20

    Html table with fixed header column and row without JS

  21. 21

    hide with js an HTML table row <tr> so that it takes up no space

  22. 22

    Filter Table Row in Html

  23. 23

    Selecting a row in a html table

  24. 24

    HTML Row table selection

  25. 25

    Filter Table Row in Html

  26. 26

    HTML Row table selection

  27. 27

    aligning the table row in HTML

  28. 28

    Send entire html table to tcpdf

  29. 29

    Table "jumps" when url is changed, angular js

HotTag

Archive