Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass array to a setAttribute method in javascript

Tags:

javascript

I want to pass few parameters to setAttribute() method parameters are :

var obj = string/this;
var mal_pat_id = "avx";
instruction = "some_instruction";
line = ['a','b','c'];

var newSelect = document.getElementById("dialog_ok_btn_for_mal_pat_conf_yes");

newSelect.setAttribute('onclick', "add("+ obj +","+ mal_pat_id + "," +    instruction + "," + line + ")");

parameter line is passed as a string, which should be passed as an array.

Thank you in advance.

like image 786
Rohan Nagalkar Avatar asked Feb 06 '23 02:02

Rohan Nagalkar


1 Answers

You should use the addEventListener() method instead :

newSelect.addEventListener("click", function(){
    add(obj, mal_pat_id, instruction, line);
});

Hope this helps.

like image 147
Zakaria Acharki Avatar answered Feb 07 '23 18:02

Zakaria Acharki