[eluser]codeboy[/eluser]
Hey All,
When I load a view, I am trying to conditionally create JavaScript statements using the syntax below. Since all of this is still happening in the view (and on the server), I expected the conditional statements to be applied (in the javascript section) but it does not seem to be. The "php if" inside the javascript section does not seem to work.
Has anyone tried something similar or do you know if there is something wrong with this?
Any help is much appreciated.
-c
Code:
//This works. Only if load_country is true, does this div appear in the html, which is what I want
<?php if ($load_country): ?>
<div id="dialog_country_search">
<?= form_input('country', $country); ?>
</div>
<?php endif ?>
<script type="text/javascript">
//This conditional statement does not seem to work and the javascript shows up in the html all the time causing errors
//since these datatables dont exist
<?php if ($load_state): ?>
$('#datatable_state').dataTable().fnClearTable();
<?php endif ?>
<?php if ($load_county): ?>
$('#datatable_county').dataTable().fnClearTable();
<?php endif ?>
};
<?php endif ?>
</script>