sammiwei
sammiwei

Reputation: 3200

alert message does not pop up

I have put the code on jsfiddle.net. The problem I am having is that the function does not seem to get called when showToast button is clicked.

The actual code
<button type="button" onClick="showAndroidToast('Hello Android!')">Show Toast</button><br/>

function showAndroidToast(name){      
        alert("hi");
}

I got the error:

ReferenceError: Can't find variable: showAndroidToast;

Anyone help? Thanks!

Upvotes: 0

Views: 1250

Answers (2)

khael
khael

Reputation: 2610

The problem is that it is not onClick but onclick, and your function should be declared in some cases like this:

<script>
 window.showAndroidToast = function(){
 //code
};
</script>
<button type="button" onclick="window.showAndroidToast('Hello Android!')">
    Show Toast
</button>

This is just to be found globally, just to be sure it is not a problem with the browser itself.

Upvotes: 1

Sudhir Bastakoti
Sudhir Bastakoti

Reputation: 100175

Remove type from your button tag:

<button onClick="showAndroidToast('Hello Android!')">Show Toast</button><br/>
//and check

Hope it helps

Upvotes: 0

Related Questions