unplugged_web Posted October 26, 2007 Share Posted October 26, 2007 I want to have a button that is clicked every 10 seconds, but don't want to user to have to click it. So my question is, is it possible to have the button automatically click itself every 10 second, but only once it's been clicked by the user?ThanksLucy Link to comment Share on other sites More sharing options...
Reg Edit Posted October 26, 2007 Share Posted October 26, 2007 I want to have a button that is clicked every 10 seconds, but don't want to user to have to click it. So my question is, is it possible to have the button automatically click itself every 10 second, but only once it's been clicked by the user?ThanksLucyYou can set a timer that executes the same code as the button click event handler every 10 seconds, once the button's been clicked once--will that do what you need? Link to comment Share on other sites More sharing options...
unplugged_web Posted October 26, 2007 Author Share Posted October 26, 2007 You can set a timer that executes the same code as the button click event handler every 10 seconds, once the button's been clicked once--will that do what you need?Yep that is exactly what I want. Is it difficult to do? Link to comment Share on other sites More sharing options...
Reg Edit Posted October 26, 2007 Share Posted October 26, 2007 Yep that is exactly what I want. Is it difficult to do?Not really. Try this:<html><head> <script type="text/javascript"> function onButtonClick() { doTheWork(); var t=setTimeout('doTheWork()',10000) } function doTheWork() { alert('work would be done here'); } </script></head><body> <input type="button" onclick="onButtonClick()" /></body></html> Link to comment Share on other sites More sharing options...
aalbetski Posted October 26, 2007 Share Posted October 26, 2007 heres one way. It just fires the event again every ten seconds. Does not actually invoke the click method of the button <input type="text" id="disp"/><button onclick="WriteTime()">click</button><script> function WriteTime() { var d = new Date(); document.getElementById("disp").innerText = d.getTime() setTimeout("WriteTime()",10000) }</script> Link to comment Share on other sites More sharing options...
unplugged_web Posted October 26, 2007 Author Share Posted October 26, 2007 Not really. Try this:<html><head> <script type="text/javascript"> function onButtonClick() { doTheWork(); var t=setTimeout('doTheWork()',10000) } function doTheWork() { alert('work would be done here'); } </script></head><body> <input type="button" onclick="onButtonClick()" /></body></html> Thank you. Sorry to sound stupid, but the button will still work with that? The code of the button at the moment is <input class="image-submit" type="image" src="images/skin/sent_sms_btn.jpg"/> Link to comment Share on other sites More sharing options...
Reg Edit Posted October 26, 2007 Share Posted October 26, 2007 Thank you. Sorry to sound stupid, but the button will still work with that? The code of the button at the moment is <input class="image-submit" type="image" src="images/skin/sent_sms_btn.jpg"/> Well, I can't tell, as there's no onclick attribute in that button declaration. You'll need to post the rest of the html and the css that goes with it (or just a link to the page, if it's online somewhere). Link to comment Share on other sites More sharing options...
unplugged_web Posted October 26, 2007 Author Share Posted October 26, 2007 Well, I can't tell, as there's no onclick attribute in that button declaration. You'll need to post the rest of the html and the css that goes with it (or just a link to the page, if it's online somewhere).I changed the code for the button to<input class="image-submit" type="image" onclick="onButtonClick()" src="images/skin/sent_sms_btn.jpg"/> The whole code is <html><head><title>Registration</title><script type="text/javascript"> function onButtonClick() { doTheWork(); var t=setTimeout('doTheWork()',10000) } function doTheWork() </script></head><body><div id="main-header"><div class="top-left-full-edge"></div><div class="top-right-full-edge"></div><div class="bottom-left-full-edge"></div><div class="text"><h1>sign-up <span class="sub">security check</span></h1></div></div><div id="content-panel"> <form id="mainForm" action="" method="post"> <spring:nestedPath path="registration"> <h2>Security check:</h2> <p> For security purposes, we need to check your mobile number and service provider. To enable us to do this we need you to send us a text message from your phone. <br/> <br/> <b>Please note we will NOT charge you for this SMS.</b> </p> <br/> <spring:bind path="*"> <c:if test="${status.error}"> <div class="error-box"> <ul> <c:forEach items="${status.errorMessages}" var="error"> <li>${error}</li> </c:forEach> Please wait a minute <img src="/image/stausbar.gif"> </ul> </div> </c:if> </spring:bind> <br/> <div id="security-code" class="cf"> <div class="left"><span class="to">Please Text:</span></div> <div> <div id="security-code-info"> <div id="security-code-box">0${registrationForm.securityCode}</div> </div> </div> </div> <br/> <p>Once you have sent the SMS please press the button below to continue.</p> <br/> <input type="hidden" name="_target3" value="3"> <input type="hidden" name="_page2" value="2"> <input class="image-submit" type="image" onClick="onButtonClick()" src="image/sent.jpg"/> </spring:nestedPath> </form> </div> </body></html> Thanks for your help Link to comment Share on other sites More sharing options...
Reg Edit Posted October 26, 2007 Share Posted October 26, 2007 I changed the code for the button to<input class="image-submit" type="image" onclick="onButtonClick()" src="images/skin/sent_sms_btn.jpg"/> The whole code is [...] Hmmm.....You didn't say the button was the submit button in a form. That makes things more complicated. It's possible to submit a form from javascript, but.....The same page will reload each time the form is submitted.The form fields will be repeatedly submitted to the server, if you do what you said.I'm not sure I understand what you're trying to do in that case........ Link to comment Share on other sites More sharing options...
unplugged_web Posted October 26, 2007 Author Share Posted October 26, 2007 Hmmm.....You didn't say the button was the submit button in a form. That makes things more complicated. It's possible to submit a form from javascript, but.....The same page will reload each time the form is submitted.The form fields will be repeatedly submitted to the server, if you do what you said.I'm not sure I understand what you're trying to do in that case........ I want the form to be resubmit every time because when the system gets the sms the next page is loaded. Sorry to be such a pain with this, but thanks for your help Link to comment Share on other sites More sharing options...
Reg Edit Posted October 27, 2007 Share Posted October 27, 2007 I want the form to be resubmit every time because when the system gets the sms the next page is loaded. [...]If you're trying to automate a repeating process that doesn't involve the user then I'd recommend you look at the server-side processing instead of repeatedly reloading a web page and faking a button-press. I should probably have thought more deeply about your original request and said this in the first place. Sorry. Link to comment Share on other sites More sharing options...
Synook Posted October 27, 2007 Share Posted October 27, 2007 If you're trying to automate a repeating process that doesn't involve the user then I'd recommend you look at the server-side processing instead of repeatedly reloading a web page and faking a button-press.Heh I once made a script that made to repeat itself 160,000 times, and it took so long that the PHP interpreter timed out. So I had to do the loops in 400-iteration blocks and use JavaScript to invoke the next block run. But for most normal scripts then just doing the loop server-side is much more efficient. Link to comment Share on other sites More sharing options...
justsomeguy Posted October 29, 2007 Share Posted October 29, 2007 This wouldn't work at all. The first time the button got clicked and the form got submitted the page would refresh and the timeout to click the button again would be gone. You would need an onload event on the second page to start a 10-second timer to submit the form after 10 seconds. Link to comment Share on other sites More sharing options...
unplugged_web Posted October 30, 2007 Author Share Posted October 30, 2007 This wouldn't work at all. The first time the button got clicked and the form got submitted the page would refresh and the timeout to click the button again would be gone. You would need an onload event on the second page to start a 10-second timer to submit the form after 10 seconds.In that case then would it be possible to have the button submit about 10-15 seconds after it has been clicked? Rather than straightaway? Link to comment Share on other sites More sharing options...
jesh Posted October 30, 2007 Share Posted October 30, 2007 Something like this? function button_Click(){ setTimeout("document.forms[0].submit();", 15000);} Link to comment Share on other sites More sharing options...
unplugged_web Posted October 30, 2007 Author Share Posted October 30, 2007 Something like this?function button_Click(){ setTimeout("document.forms[0].submit();", 15000);} Great thanks for that, I guess I put that bit in the head section and would this work for the button?<input class="image-submit" type="image" onclick="button_Click()" src="images/skin/sent_sms_btn.jpg"/> Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.