Questions tagged [onclick]

An event which occurs when user clicked an object. It is a combination of two events, that is, "onmousedown" and "onmouseup".

Tag Usage

This tag is used frequently on questions surrounding Javascript event handling. It is worth noting that virtually every conceivable question has been asked on this topic so before you hit that post your question button, have you had a quick look to see if your question has already been covered?

14616 questions
185
votes
10 answers

Attaching click event to a JQuery object not yet added to the DOM

I've been having a lot of trouble attaching the click event to a JQuery object before adding it to the DOM. Basically I have this button that my function returns, then I append it to the DOM. What I want is to return the button with its own click…
danielrvt
  • 10,177
  • 20
  • 80
  • 121
181
votes
8 answers

Add disabled attribute to input element using Javascript

I have an input box and I want it to be disabled and at the same time hide it to avoid problems when porting my form. So far I have the following code to hide my input: $(".shownextrow").click(function() { …
user342391
  • 7,569
  • 23
  • 66
  • 88
175
votes
7 answers

onclick() and onblur() ordering issue

I have an input field that brings up a custom drop-down menu. I would like the following functionality: When the user clicks anywhere outside the input field, the menu should be removed. If, more specifically, the user clicks on a div inside the…
1''
  • 26,823
  • 32
  • 143
  • 200
171
votes
8 answers

How do I add a simple onClick event handler to a canvas element?

I'm an experienced Java programmer but am looking at some JavaScript/HTML5 stuff for the first time in about a decade. I'm completely stumped on what should be the simplest thing ever. As an example I just wanted to draw something and add an event…
Jer
  • 5,468
  • 8
  • 34
  • 41
164
votes
7 answers

Including both href and onclick to HTML tag

If I have this element: Item How can I make both href and onClick work, preferably with onClick running first?
user1589113
153
votes
9 answers

Call two functions from same onclick

HTML & JS How do I call 2 functions from one onclick event? Here's my code the two functions being pay() and cls(). Thanks!
user182
  • 1,805
  • 5
  • 18
  • 18
152
votes
13 answers

handle textview link click in my android app

I'm currently rendering HTML input in a TextView like so: tv.setText(Html.fromHtml("test")); The HTML being displayed is provided to me via an external resource, so I cannot change things around as I will, but I can, of course,…
David Hedlund
  • 128,221
  • 31
  • 203
  • 222
148
votes
17 answers

How can I simulate an anchor click via jquery?

I have a problem with faking an anchor click via jQuery: Why does my thickbox appear the first time I click on the input button, but not the second or third time? Here is my code:
prinzdezibel
  • 11,029
  • 17
  • 55
  • 62
147
votes
20 answers

Call ASP.NET function from JavaScript?

I'm writing a web page in ASP.NET. I have some JavaScript code, and I have a submit button with a click event. Is it possible to call a method I created in ASP with JavaScript's click event?
MattSayar
  • 2,078
  • 6
  • 23
  • 28
139
votes
9 answers

python selenium click on button

I am quite new to python selenium and I am trying to click on a button which has the following html structure:
AJW
  • 5,569
  • 10
  • 44
  • 57
131
votes
9 answers

Why is this jQuery click function not working?

Code: The…
starbucks
  • 2,926
  • 9
  • 41
  • 53
130
votes
8 answers

How to pass a view's onClick event to its parent on Android?

I have a TextView in a layout whos background is a Selector. And the TextView's text is set to Spanned from HTML. Then I set the TextView with the LinkMovementMethod. Now when I tap on the TextView, the click event is not sent to its parent layout…
shiami
  • 7,174
  • 16
  • 53
  • 68
126
votes
8 answers

Uncaught ReferenceError: function is not defined with onclick

I'm trying to make a userscript for a website to add custom emotes. However, I've been getting a lot of errors. Here is the function: function saveEmotes() { removeLineBreaks(); EmoteNameLines = EmoteName.value.split("\n"); EmoteURLLines…
ECMAScript
  • 4,439
  • 4
  • 21
  • 29
121
votes
10 answers

How can I disable HREF if onclick is executed?

I have an anchor with both HREF and ONCLICK attributes set. If clicked and Javascript is enabled, I want it to only execute ONCLICK and ignore HREF. Likewise, if Javascript is disabled or unsupported, I want it to follow the HREF URL and ignore…
Ky -
  • 30,724
  • 51
  • 192
  • 308
114
votes
21 answers

How to prevent the activity from loading twice on pressing the button

I am trying to prevent the activity from loading twice if I press the button twice instantly after the first click. I have an activity which loads on click of a button, say myButton.setOnClickListener(new View.OnClickListener() { public void…
tejas
  • 2,435
  • 10
  • 37
  • 54