You need to sign in to do that
Don't have an account?

Need help regarding commandButton "Action" and "OnClick"
I am trying to implement online exam functionality in which I would like to restrict user to submit answers till time assigned for that page i.e. 10 minutes.
I tried like this in VF page.
<script> function myfunction() { if(c!=0.00) { var temp; temp=setTimeout(function(){alert("You can not submit your answers now ")},1000); } } </script>
This is the syntax for commandButton.
<apex:commandButton value="Submit" action="{!submit}" onclick="myfunction();"/>
But every time when user tries to click on "Submit" button before time end it's allowng to click.
I would like to show an alert if user is cliclking on Submit before time end.
Could anyone suggest in this case.
Thanks,
JaanVivek
Hi,
Try this....
function mySubmit() {
if(c!=0.00){
var temp=setTimeout(function(){alert("You can not submit your answers ")},1000);
return false;
}
}
<apex:commandButton value="Submit" action="{!submit}" onclick="return mySubmit();"/>
All Answers
myfunction isn't called until the user clicks the button, so they would be allowed to submit the page. Instead, do something like this:
You will also probably want to place some sort of timer on the page so they have a visual indication before the button becomes disabled and they are unable to continue.
hi ,,
plz do like this it may help you...
use the actionpoller componet in vf page and then set intervel time as 10 mints..
if u want error add error message in the submint method;
for example use this code as reference
<apex:page controller="exampleCon">
<apex:form>
<apex:outputText value="Watch this counter: {!count}" id="counter"/>
<apex:actionPoller action="{!incrementCounter}" rerender="counter" interval="15"/>
</apex:form>
</apex:page>
/*** Controller: ***/
public class exampleCon {
Integer count = 0;
public PageReference incrementCounter() {
count++;
return null;
}
public Integer getCount() {
return count;
}
}
.....................................
here u can implement the login in the submit method like
if(getcount>=10)//here set ur time in sec's
{
addError();
}
regards......
Balu
Thank you for your suggestions.
In my VF Page i used following javascript to show timer in "0.10" format, after every 1 minute it will decrease it by 1 i.e. "0.09" and it will keep on till "0.00".
javascript-
I it I have applied alert after 5 minutes and an another alert when time left is 1 minute.
Now i want to show one alert if before the end time i.e. 0.00 (after 10 minutes) anyone is trying to click the submit button and page should not be refreshed.
I have already an VF page and Corresponding controller.
I was trying to use "onclick" in commandbutton but it did not work.
I tried like this.
Please suggest anything in above script.
Thanks
JaanVivek
Hi,
Try this....
function mySubmit() {
if(c!=0.00){
var temp=setTimeout(function(){alert("You can not submit your answers ")},1000);
return false;
}
}
<apex:commandButton value="Submit" action="{!submit}" onclick="return mySubmit();"/>
Thanks for your reply.
I tried it and it was working but othe rthan this my all alert were not working like.
if(c==0.05)
{
myVar=setTimeout(function(){alert("Only 5 minutes are left")},1000);
}
else if(c==0.00)
{
myVarOne=setTimeout(function(){alert("Please submit your answers ")},1000);
}
here is my whole script.
And after time reches to "0.00" it was not submitting the answers.
Could you please help in this.
Thanks,
JaanVivek
It's working now.
there was some network issue.
Thanks,
JaanVivek