У меня возникают проблемы с моим вложенным циклом. Я пытаюсь определить значение отмеченных флажков в моей форме. Мне сказали, что все это должно отформатирован так:Uncaught TypeError: У объекта нет метода 'setAttribute'
for(checkboxes loop){
for(item.appointmentType[1] loop){
if(statement conditional){
set checks code
}
}
}
Но я просто не могу показаться, чтобы получить это написано правильно, потому что я получил сообщение об ошибке сказав, Uncaught TypeError: Объект не имеет метод «SetAttribute»
Ниже приведен код, с которым я работаю. Может кто-нибудь помочь мне исправить это, что может знать, о чем я говорю?
var checkboxes = document.forms[0].appointmentType;
for(var i=0; i<checkboxes.length; i++){
for(var j=0; j<item.appointmentType[1].length; j++){
if(checkboxes[i].value === item.appointmentType[1][j]){
item.appointmentType[1][j].setAttribute("checked", "checked");
}
}
}
Вот код HTML, который сочетается с javascript. Все javascript содержится в собственном файле .js.
<ul><span class="lab">
<li><input type="checkbox" checked value="Get A Free Estimate" id="Get A Free Estimate"
name="appointmentType" /><label for="getAFreeEstimate"><span class="gfe">Get A FREE
Estimate</span></label></li>
<li><input type="checkbox" value=" Lawn Service" id="lawnService" name="appointmentType"/
<label for="lawnService"><span class="ls">Lawn Service</span></label></li>
<li><input type="checkbox" value=" Sprinkler System Service" id="sprinklerSystemService"
name="appointmentType" /><label for="sprinklerSystemService"><span
class="sss">Sprinkler System Service</span></label></li>
<li><input type="checkbox" value=" Flower Bed Maintenance" id="flowerBedMaintenance"
name="appointmentType" /><label for="flowerBedMaintenance"><span class="fbm">Flower
Bed Maintenance</span></label></li>
<li><input type="checkbox" value=" Hedge/Tree Service" id="hedgeTreeService"
name="appointmentType" /><labe for="hedgeTreeService"><span class="hts">Hedge/Tree
Service</span></label></li>
<li><input type="checkbox" value=" Handyman Services" id="handymanServices"
name="appointmentType" /><label for="handymanServices"><span class="hs">Handyman
Services</span></label></li>
<li><input type="checkbox" value=" Other" id="other" name="appointmentType" /><label
for="other"><span class="otr">Other</span></label></li></span></ul><br/>
Как этот товар должен быть ценным? – Pointy
Не могли бы вы показать HTML, который идет с этим кодом? – Barmar