I have very little experience with JavaScript however I am attempting to write a function which pushes checkbox values from one array to another. I have written the following code, however it doesn't appear to work. Any help is appreciated.
var pages = document.forms['frm_list'].elements[ 'pages[]' ];
var selected = document.forms['frm_list'].elements[ 'selectedPages[]' ];
console.log(pages);
console.log(selected);
// using reference to sports obtained above
for (var i=0, len=pages.length; i<len; i++) {
pages[i].onclick = addPage;
}
function addPage() {
if ( this.checked ) {
console.log(this);
selected.push(pages);
alert( this.value );
} else {
alert( this.value );
}
}
Aucun commentaire:
Enregistrer un commentaire