getElementById.innerHTML with if else condition

CadeLewis picture CadeLewis · Sep 30, 2014 · Viewed 9.7k times · Source

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.

Answer

tymeJV picture tymeJV · Sep 30, 2014

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

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