Jump to content

button reloading?


unplugged_web
 Share

Recommended Posts

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
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?
Link to comment
Share on other sites

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

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

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

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

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

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

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

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

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

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...