[Answered ]-Unable to fetch row elements values using Javascript

1πŸ‘

βœ…

In your template you have rows like

<input type="text" class="form-control" name="dose", id="dose">

It seems that each input does not have its unique id, so when you click the button on any row you get the same result. The solution could be modifying backend part with something like this:

<input type="text" class="form-control" name="dose", id="{{ item.somedoseid }}">
πŸ‘€Alecx

0πŸ‘

Another solution may be with pure JS only (if it is more convenient or as an example):

<button class="btn btn-light bx bx-plus" type="button" id="qty" onclick="
addItem({
'dose':this.parentNode.parentNode.children[1].firstElementChild.value,
'quantity':this.parentNode.parentNode.children[2].firstElementChild.value,
'name':'{{item.item_name}}',
'code':this.name,
'usage':{'morning':this.parentNode.parentNode.children[3].children[0].firstElementChild.checked,
'afternoon':this.parentNode.parentNode.children[3].children[1].firstElementChild.checked,
'evening':this.parentNode.parentNode.children[3].children[2].firstElementChild.checked,
'night':this.parentNode.parentNode.children[3].children[3].firstElementChild.checked,
'sos':this.parentNode.parentNode.children[3].children[4].firstElementChild.checked} })">BtnText</button>
πŸ‘€Alecx

Leave a comment