Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

onclick event is not triggering

Tags:

javascript

<script type="text/javascript">
 function accept(s)
  {
    alert(s);
  }
 </script>

<input type="button" style="background-color:#e2e6f0;border:1px solid 
#DCDCDC;padding-left:5px;padding-right:5px;padding-top:3px;padding-bottom:3px" 
value="accept" onclick="accept('28391135292739653997')">

Why the onclick event not triggering the accept function? I was expecting it to work. I thought it might be due to number of digits but it worked in my sample where I used 30 digits too. Where is my mistake?

like image 658
niko Avatar asked Mar 02 '26 20:03

niko


2 Answers

It's because accept is the name of a property of the input element. So the onclick event is trying to call the accept property as a method, rather than the accept function you've defined. If you change it to:

onclick="window.accept('28391135292739653997')"

It will call the globally defined accept function.

like image 193
Stoo Avatar answered Mar 04 '26 09:03

Stoo


It seems to work if you call it something other than accept:

http://jsfiddle.net/Bt5Q3/

like image 40
James McLaughlin Avatar answered Mar 04 '26 09:03

James McLaughlin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!