function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
chowdary marellachowdary marella 

Creating Online exam

When creating a online exam on vf page,how to build logic.?? when i click on start exam(button),the javascript BACK timer and question should start coming randomly with out repeating and start exam button should dissapear after user click.how to do this?? am having prblm to call both javascript and apex methods at a time on button click..here is my code please resolve ..


vf page:-


<apex:page sidebar="false" showHeader="false" controller="clsonline">
<form>
<html>
<body style="background-image:url('{!$Resource.Background}');">

<table border="1" cellpadding="14px" width="1200px" align="center" style= "font-size:25px; color: #686868 ;font-family:Verdana;">
<tr><th><center>SalesForce DEV-401 Examination</center></th></tr>
</table>
<table border="1" cellpadding="210px" width="1300px" style= "font-size:25px; color:#F00000 ;font-family:Verdana;">
<tr><td width="12%">

</td>

<td width="6px"> Answer the Following<BR/><BR/><BR/>
<apex:pageBlock >
<apex:pageblockTable value="{!quess}" var="ques" columnsWidth="100%, 100%" >
<apex:column value="{!ques.Name}" headerValue=""/>
<apex:column value="{!ques.a__c}" headerValue=""/>
<apex:column value="{!ques.b__c}" headerValue=""/>
<apex:column value="{!ques.c__c}" headerValue=""/>
<apex:column value="{!ques.d__c}" headerValue=""/>
</apex:pageblockTable>

</apex:pageBlock>
<!-- TIMER CODING STARTS / -->

<script type="text/javascript">

var sec = 00; // set the seconds
var min = 60; // set the minutes

function countDown() {
sec--;
if (sec == -01)
{
sec = 59;
min = min - 1;
}
else 
{
min = min;
}

if (sec<=9)
{
sec = "0" + sec; 
}

time = (min<=9 ? "0" + min : min) + " min and " + sec + " sec ";

if (document.getElementById) { document.getElementById('theTime').innerHTML = time; }

SD=window.setTimeout("countDown();", 1000);
if (min == '00' && sec == '00') { sec = "00"; window.clearTimeout(SD); }
}
<!--window.onload = countDown;-->

</script>

<style type="text/css">

.timeClass {
font-family:arial,verdana,helvetica,sans-serif, color:yellow;
font-weight:normal;
font-size:20pt;
}

</style>

<!-- This goes into the BODY of the file -->

<table width="100%">
<tr><td width="100%" align="center"><span id="theTime" class="timeClass"></span></td></tr>
</table>

<div id="mydiv"></div>


<center><input type= "button" id="button1" value="StartExam" onclick="countDown()" /></center>
<apex:form >
<!--<apex:commandButton onclick="countDown();" action="{!Ques}" value="Start Exam"/>-->
<apex:commandButton value="Next" action="{!nxt}"/>
<!--<apex:commandButton value="start exam" onClick="if(!countDown()) return true;" action="{!CallAction}" rendered="{!hidebttn}" />-->
</apex:form>

</td><td width="22%">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <apex:image url="{!$Resource.pic}" width="80" height="50"/></td> </tr>
</table>
<table border="1" cellpadding="14px" width="1000px" align="center" style= "font-size:15px;color:#660000;font-family:Verdana;">
<th > <center><marquee behavior="alternate">360 Degree Cloud 2013.All Rights Reserved</marquee></center> </th>
</table>
</body>
</html>
</form>
</apex:page>

 

======================================================================

 

 

CONTROLLER:-

 

public class clsonline { 
public boolean hidebttn{get;set;}
public list<Questions__c> quess{get;set;}
set<integer> i= new set<integer>();
public pageReference CallAction() {


pageReference pgref=new pageReference('/apex/onlineexam?pagID=1');
pgref.setRedirect(true);

return pgref;

}
public integer timer;
list<Questions__c> ques=new list<Questions__c>();

public clsonline(){

hidebttn=true;
if(ApexPages.currentpage().getParameters().get('pagID')!=null)

hidebttn=false;
}
}
public pageReference Ques()
{


Integer rand = Math.floor(Math.random()*14).intValue();


quess = new list<Questions__c>();
if(!i.contains(rand)){
quess = [SELECT Name FROM Questions__c limit 1 OFFSET :rand];
}
i.add(rand);
System.debug('@@@@Account@@@@@'+quess); 
return null;
}
public pagereference nxt()
{
Integer rand = Math.floor(Math.random()*14).intValue();

quess = new list<Questions__c>();
if(!i.contains(rand)){
quess = [SELECT name,a__c,b__c,c__c,d__c FROM Questions__c limit 1 OFFSET :rand];
}
System.debug('@@@@Account@@@@@'+quess); 
return null;
}
}