0

I have the code below that turns ON my phones LED flash every time the button is clicked, but I also need the LED to turn OFF automatically after 3 seconds. Not sure how to do it, please help.

input type="button" onclick="ipwajax('enabletorch')" value="Turn on LED"

Sam
  • 3
  • 1
  • 6

1 Answers1

0

Assuming ipwajax('enabletorch') enables the LED, and ipwajax('disabletorch') disables it, you would want something like

<script language="JavaScript">

  function enableTorch(milliSeconds) {
    ipwajax('enabletorch');
    window.setTimeout("ipwajax('disabletorch');",milliSeconds);
  }

</script>

<input type="button" onclick="enableTorch(3000);" value="Turn on LED">
Eugen Rieck
  • 64,175
  • 10
  • 70
  • 92
  • So I just replace the: input type="button" onclick="ipwajax('enabletorch')" value="Turn on LED" with everything you gave me above then and it should work? – Sam Feb 07 '13 at 11:49
  • it is best to move the function to your topping script block, but it should work even this way. – Eugen Rieck Feb 07 '13 at 12:28
  • Thanks so much, i now need to test this. really hope it works. You're the best. – Sam Feb 07 '13 at 21:52