EchoFool Posted May 12, 2010 Share Posted May 12, 2010 Hey I have a form which is this: <form method="POST" action=""> <input id="btn1" type="submit" name="test1" value="Test"> <input id="btn2" type="submit" name="test2" value="Test2"> <input id="btn3"type="submit" name="test3" value="Test"> </form> What im trying to do is change my current JS which currently affects one button to now affect all 3 buttons! So all 3 will be disabled for 3 seconds on "page load" and show a animation of: " Wait.. 3 Wait.. 2 Wait.. 1 " Then show its real button value as shown in the form when the timer expires. My current JS only works on one button which is this: <script type="text/javascript"> var b = 0; function counter() { var btn1 = document.getElementById('btn1'); btn1.disabled = true; if (b < 2) { btn1.disabled = true; btn1.value = 'Wait... ' + (2-b); b++; setTimeout("counter()", 1000); } else { btn1.disabled = false; btn1.value = 'test1'; } } window.onload = function() { counter(); } </script> Could you please help on how i can change it to affect all 3 buttons as my current script only works on one ? Link to comment https://forums.phpfreaks.com/topic/201439-help-edit-js/ Share on other sites More sharing options...
tomfmason Posted May 12, 2010 Share Posted May 12, 2010 There may be a better way to do this but here is a quick and dirty(working) solution var b = []; var buttons = ["btn1","btn2","btn3"] var btn = [] function counter(id,n) { btn[n] = document.getElementById(id); btn[n].disabled = true; if (b[n] < 2) { btn[n].disabled = true; btn[n].value = 'Wait... ' + (2-b[n]); b[n]++; setTimeout("counter('"+id+"',"+n+")", 1000); } else { btn[n].disabled = false; btn[n].value = 'test'+(n+1); } } window.onload = function() { for(var i=0;i<buttons.length;i++){ b[i] = 0; counter(buttons[i],i); } } Link to comment https://forums.phpfreaks.com/topic/201439-help-edit-js/#findComment-1056920 Share on other sites More sharing options...
EchoFool Posted May 12, 2010 Author Share Posted May 12, 2010 What do you mean by dirty ? Link to comment https://forums.phpfreaks.com/topic/201439-help-edit-js/#findComment-1056937 Share on other sites More sharing options...
tomfmason Posted May 12, 2010 Share Posted May 12, 2010 What do you mean by dirty ? basically the code I posted should serve the intended purpose but there is most likely a better way to do it. Link to comment https://forums.phpfreaks.com/topic/201439-help-edit-js/#findComment-1056938 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.