0

The code is simple:

var td1 = document.createElement("td");
td1.id="td_radio_"+nr_int+"_"+nr_var2;
td1.style.border = "0";
td1.style.width = "5%";
td1.onclick="adaugare_varianta_simplu(\'"+nr_int+"\',\'"+nr_var2+"\');";

but the function doesn't fire when I click the cell; what am I doing wrong? I'm not using bind because later on there's gonna be a removeAttr working on it so I want it set up as an attribute.

2 Answers 2

2

You are assigning a string as event handler so it can not be executed, below is more what you are after I think.

var td1 = document.createElement("td");
td1.id="td_radio_"+nr_int+"_"+nr_var2;
td1.style.border = "0";
td1.style.width = "5%";
td1.onclick = function() {
    adaugare_varianta_simplu(nr_int,nr_var2);
};
Sign up to request clarification or add additional context in comments.

1 Comment

This worked, thanks. I thought it should work like any other attribute, i was wrong.
2

Think you need this:

td1.onclick="function(){adaugare_varianta_simplu(\'"+nr_int+"\',\'"+nr_var2+"\');}";

You have to wrap the event in a function.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.