I'm trying to append text within an HTML file, but only when is_sum_1 == true
. I want the user to select something from a dropdown box before the conditional text gets appended, but the if
statement seems to only become satisfied when var is_sum_1 = true;
is outside of the function.
JavaScript function:
function dropDownListener(input_id, output_id) {
var dropDown = document.getElementById(input_id);
var is_sum_1 = true;
dropDown.onchange = function() {
document.getElementById(output_id).innerHTML = dropDown.value;
}
dropDownListener('sum_1', 'print_sum_1');
Printing output and conditional text in HTML:
<div id="summary">
<span id="print_sum_1"></span>
<script>
if (is_sum_1) {
$('#summary').append("I'm trying to append text if condition met")
}
</script>
</div>