I would like to add multiple lines of code to "myContent1" without having to replicate it as this can be quite tedious. Is there a more efficient way? Thanks!
function getCode(form){
myContent1 = document.inputForm.myContent1.checked;
output =
'<!DOCTYPE html>\n' +
'<html>\n' +
'<body>\n' +
((myContent1) ? '<div>content 1</div>' : '') + '\n' +
((myContent1) ? '<div>content 2</div>' : '') + '\n' +
'' +
'<\/body>\n' +
'<\/html>\n';
document.inputForm.source.value = output;
return output;
}
ifblock instead, but you could use a single ternary expression to concatenate several strings all at once:(myContent1 ? '<div>content 1</div><div>content 2</div>' + '<div>content 3</div>' + someVar + '<whatever>' : '').