0

I manipulated some html to display a little form in a modal bootstrap like this :

$.each(response, function(i, item){
    detail += "<div><input name='detail-tipe' type='checkbox' value='" + response[i].nama_detail + "' class='detail-tipe' /> " + response[i].nama_detail.toString() + "</div>";
});

detail +=  "$('.detail-tipe').each(function(){
    var attrib = $(this).attr('value');
    for ( var j=0, k = remo.length; j < k; j++ ) {
        if(attrib == remo[j]){
            $(this).attr('checked', 'checked');
        };
    }
})";

But, dollar sign is unterminated. Is it possible Please, advise.

llanato
  • 2,508
  • 6
  • 37
  • 59
Fadly Dzil
  • 2,154
  • 3
  • 34
  • 85

1 Answers1

1

If you want to assign a multi-line string to a variable, you need to put a \ at the end of each line to tell the interpreter that the string is continuing. Otherwise it thinks you want to start a new line of actual code.

detail += "$('.detail-tipe').each(function(){ \
  var attrib = $(this).attr('value'); \
  for ( var j=0, k = remo.length; j < k; j++ ) { \
    if(attrib == remo[j]){ \
        $(this).attr('checked', 'checked'); \
    }; \
  } \
})";
ADyson
  • 57,178
  • 14
  • 51
  • 63