lundi 8 mai 2017

Setting specific checkbox element in form array using javascript

I have a form that has an array of checkbox elements, such as this:

etc.

I have also a trash icon displayed with each checkbox :

etc.

Now, when I click one of the trash icons, I switch the trash.png image with trash-remove.png image and I try to set the associated checkbox to "true". I get the image changed BUT I cannot get the associated checkbox to show "checked".

Below is my remFavorite javascript code:

function remFavorite(id, container) {

document.getElementById(container).innerHTML = '<img src="/ideabooks/images/trash-removed.png" onClick="addFavorite(&#34;'+id+'&#34;, &#34;'+container+'&#34;, &#34;'+fid+'&#34;)"></div><input type="hidden" name="rem['+id+']" value="Yes" />';
var checkboxes = document.getElementsByName('select[]');
checkboxes[id].checked=true;
checkboxes[id].value="on";

alert("6 id="+id+" checkedbox[id]="+checkboxes[id].checked+" checkedbox[id]="+checkboxes[id].value); }

The Alert on line 6 shows that checkboxes[1].checked is set to "true" and that checkboxes[1].value is set to on", but when the script completes, the checkbox is not checked??

You help is greatly appreciated:)




Aucun commentaire:

Enregistrer un commentaire