Search code examples
javascripthtmlif-statementbusiness-catalyst

getElementById.innerHTML with if else condition


I have coded this in Business Catalyst website.

<li class="instock"><span id="stock">Stock</span><span id="stockcount" style="display: none;">{tag_instock}</span> </li>

<script>
var stockcnt = document.getElementById('stockcount').innerHTML;
if (stockcnt==0){
 document.getElementById('stock').InnerHTML="Out of Stock";
}else{
document.getElementById('stock').InnerHTML="In Stock";
}
</script>

What i want to do is if stockcount == 0 change the innerHTML of stock

{tag_instock} will automatically generate number according to the stock count when page loads.

when i tried this code. it didn't work. can anyone show me what I'm doing wrong here.


Solution

  • JavaScript is case-sensitive, its innerHTML (lose the capital "I")

    document.getElementById('stock').innerHTML="In Stock";