hi ,
i am trying to add a label from javascript but im getting error
what i did was:
document.getElementById(option).innerHTML="<label onclick='updateInfo('edit','qualification',"+data_id+","+data+")>"+data+"</label>";
what am i doing wrong ?
hi ,
i am trying to add a label from javascript but im getting error
what i did was:
document.getElementById(option).innerHTML="<label onclick='updateInfo('edit','qualification',"+data_id+","+data+")>"+data+"</label>";
what am i doing wrong ?
I think the error is with the quotes inside the function. You have to escape the quotes.
document.getElementById('option').innerHTML="<label onclick=\"updateInfo('edit','qualification','"+2+"','"+test+"')\">"+data+"</label>";
The quotes are wrong. you've used single-quotes to quote the onclick value and it's contents.
onclick='updateInfo('edit','qualification',"
Another way is to use document.createElement() and document.appendChild() to avoid the escaping. It also makes the code more readable.
var option = document.getElementById("option_id");
var label = document.createElement("label");
label.onclick = function() {
updateInfo('edit','qualificn',"'" + data_id + "'", "'" + data + "'")
}
label.innerHTML = data;
option.appendChild(label);