Emo333 Emo333 - 2 months ago 19
Javascript Question

Razor View Page html button onclick attribute will not recognize variable in nested code block

Why is the

id
variable not recognized in context of this js function on this cshtml page:

function btnDowClick(idE) {
var id = "#Dow" + idE + " ";
var id2 = 1;
$(id).html("<input id='inpDow' class='form-control' onclick='' class='aDow'></input>" +
"<button id='btnCancel' class='btn btn-primary' onClick='btnCancelOnClick(@(id2))'>Cancel</button>");
}
function btnCancelOnClick(id) {
//turn <input> and <button> back into <a>
}

Answer

ohh sorry... now i understand try this

   function btnDowClick(idE) {
    var id = "#Dow" + idE + " ";
    var id2 = 1;
    $(id).html("<input id='inpDow' class='form-control' onclick='' class='aDow'></input>" +
    "<button id='btnCancel' class='btn btn-primary' onClick='btnCancelOnClick("+id+")'>Cancel</button>");
}
function btnCancelOnClick(id) {
    //turn <input> and <button> back into <a>
}
Comments