0

I am expecting that the on button click action should popup the alert message. But I am unable to figure out the root cause that code doesn't work as expected.

Here is my code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<body>

<script type="text/javascript">
function click() {
alert("this is an alert");
}
</script>

<form>
<input type="button" value="Click Here" onclick="click()" />
</form>

</body>
</html>
ddmps
  • 4,350
  • 1
  • 19
  • 34
  • Have you checked your Javascript console for any errors…? – deceze Jul 07 '17 at 08:13
  • yes there are no errors in my console – chriswebbonline Jul 07 '17 at 08:20
  • 1
    Duplicate: https://stackoverflow.com/questions/31613748/why-cant-i-call-a-function-named-clear-from-an-onclick-attribute/31613889#31613889 – Quentin Jul 07 '17 at 08:26
  • This is giving you error because 'click' is overridden by window.click method. Change name of click function like showMsg() and it will work fine. I have tested it and it is working fine. I am unable to post an answer because your question is on hold. Here is a codepen link https://codepen.io/upasanak/pen/GEXmvb – Upasana Jul 07 '17 at 08:35
  • I see! wow thanks brother, newbie mistake. – chriswebbonline Jul 07 '17 at 08:44

1 Answers1

0

There is click() function corresponding to button in JavaScript. Try using window.click()

<input type="button" onclick="window.click()" value="click me"/>
Abhay
  • 3,151
  • 1
  • 19
  • 29