How to loop through item card checkboxes with same id? (Javacsript/ JQuery)

تبليغ
سؤال

يرجى شرح بإيجاز لمإذا تشعر أنك ينبغي الإبلاغ عن هذا السؤال.

تبليغ
‎إلغاء

Good day everyone, I am not sure how can I loop through multiple item card with 2 checkboxes of the same ID (within each card).

Currently my main issue is that whenever my code meets a specific condition, it only renders the first item card checkboxes as the id points to it.

I need the checkboxes to render accordingly to the key value pairs that are uniquely stored in the local storage. I am not sure how I can loop through this? Can somebody help me on this? Thank you 🙂

Html Code:

<form class=”g-item-title” style=”color: #005e95″>
<input type=”radio” id=”checkboxPartialDownload” data-dojo-attach-event=”onClick: _test” style=”cursor: pointer;” name=”downloadValue” value=”partialDownload” class=”classPartialDownload” checked>
Allow Partial Download
<br>
<input type=”radio” id=”checkboxFullDownload” data-dojo-attach-event=”onClick: _onclickTest” style=”cursor: pointer;” name=”downloadValue” value=”fullDownload” class=”classFullDownload”>
Allow Partial + Full Download
</form>

JS Code that renders when page loads:

render: function (hit) {

let dataTitle = hit.sort[0];
let dataid = hit._source.fileid;

$(“input[type=’radio’][name=’downloadValue’]:checked”).each(function(){

if(localStorage.getItem(`${dataTitle}`) === “FullDownload”){
var value=$(this).attr(‘value’);

if(value ===’partialDownload’){
$(‘#checkboxPartialDownload’).prop(‘checked’, false); //Only renders the first item checkboxes..
$(‘#checkboxFullDownload’).prop(‘checked’, true);
}
}
})

On click function that saves the key value pair to local storage:

_onclickTest:function(evt){
let title = this.item.title;
let fileid = this.item.fileid
localStorage.setItem(`${title}`,’FullDownload’)
}

0
X 5 أشهر 2022-07-10T12:05:26+03:00 0 إجابة 0 مشاهدات مبتدئ 0

‫أضف إجابة

تصفح
تصفح

مجهول يجيب