0

In the following javascript code,

            needSubIdCheck = $("#needSubIdCheck").text();
liveSupplierCount = $("#liveSupplierCount").text();
subIdCount = $("#subIdCount").text();

if(needSubIdCheck == 'true')
{
    if( liveSupplierCount > subIdCount  )
    {
        alert("subIDS Needs to be assigned");
        return false;
    }
}

The above code gives, "Uncaught TypeError: alert is not a function" in the console. If I change the alert with window.confirm or console.log everything is fine. Can anyone help me to come out of this problem?

  • 2
    Problem here is you treat asynchronous calls as if they are synchronous. You order a pizza and as soon as you hang up the phone, you expect to eat it. But in reality you need to wait for the callback to fire. So the code that lives outside of the callback should live inside of it. – epascarello Jul 07 '17 at 13:43
  • @epascarello How would that explain the error message? `alert is not a function` – BenM Jul 07 '17 at 13:44
  • 2
    @BenM no clue what that is, but the issue here is the fact the OP is trying to access data that has not been set yet. – epascarello Jul 07 '17 at 13:45
  • 2
    We can't answer the `alert is not a funciton` question because the OP hasn't given us any recreation steps. – Liam Jul 07 '17 at 13:45
  • @Chanramohan if you think it's not a duplicate, you should probably explain why. I see you've edited the code. Explain what you've done and what the problem still is. If you've got an issue with putting alerts in there as you describe, then show the version with alerts in. You can't expect us to fix code that we can't see. – ADyson Jul 07 '17 at 15:15

0 Answers0