mardi 6 janvier 2015

insert javascript function in html code

I need to associate a dynamic javascript function with checkbox along with other data in an array. For example. I have the following javascript array:



var arr = ['hello', 'world'];
arr.unshift('buddy');
var index = 1;
arr.unshift('<input type="checkbox" id = "' + index + '" onchange="boxChange(" + index + ")>');


The first element in the above array is a checkbox that has an onchange event. The event triggers the function boxChange that has the index passed in.


but the above checkbox event doesn't work, I guess the syntax (quotes) is not right. I need some help with correcting the "quotes". Thanks


I have an imcomplete code written in jsFiddle here http://ift.tt/1Ki2WPw





Aucun commentaire:

Enregistrer un commentaire