-1

How would I dynamically click a button again once it is clicked once by the user?
For example:

<input type='button' value='Click me once, and I will click twice!' onClick='click button again using JavaScript' />

So I want to click the button, and have the button click it's self again.
Is this possible, and how would I do this?
Thanks!

pattyd
  • 5,927
  • 11
  • 38
  • 57
  • 1
    *"So I want to click the button, and have the button click it's self again."* Why? If you tell us what your real goal is, we will almost certainly be able to offer you a better solution. – T.J. Crowder Jun 01 '13 at 17:12
  • So you want the `doubleclick` handlers called? And are you using any libraries? (jQuery, Closure, Prototype, ...) – T.J. Crowder Jun 01 '13 at 17:13
  • @T.J.Crowder I would like to do this with pure JavaScript. Would the click() function work here? – pattyd Jun 01 '13 at 17:16
  • @ pattyd: Using a library doesn't mean you're not using "pure" JavaScript. If you mean you don't want to use anything other than the JavaScript functions defined in the spec and the ones provided by the DOM functions, okay. Can you answer the other questions? – T.J. Crowder Jun 01 '13 at 17:19
  • try this http://stackoverflow.com/questions/2381572/how-can-i-trigger-a-javascript-event-click – Devjit Jun 01 '13 at 17:21
  • 1
    @T.J.Crowder looking back at this question 8 years later I am also curious what my actual goal was – pattyd Jan 14 '21 at 17:54
  • 1
    @pattyd - LOL! I've done that. :-D – T.J. Crowder Jan 14 '21 at 18:07

1 Answers1

1

maybe something like this is what you're looking for

HTML

<input type='button' value='Click me once, and I will click twice!' onClick='clickclick();' />

JS

function clickclick(){
    alert("click");
    reclick();
}    
function reclick(){
    alert("reclick");
}

working example : http://jsfiddle.net/eQdBY/


EDIT

to trigger the click behaviour, use onclick:

 document.getElementById("btn").onclick();

anyway, I think that recalling the button click inside the button onclick event, will take you to an infinite loop, so you should use two separate functions or use a "click counter" to handle that.

example of onclick usage: http://jsfiddle.net/eQdBY/1/

Josh Crozier
  • 233,099
  • 56
  • 391
  • 304
BeNdErR
  • 17,471
  • 21
  • 72
  • 103