2
Answers

javascript for Update Panel

Ask a question
PRABIN YOVAN

PRABIN YOVAN

13y
7.8k
1
Dear All,
I got confused with this issue since last two three days.
What I need is I want ot call a javascript only first time of the page load.
My application is an Online Test with limited time period. When the user starts to take up the test, the time should start. Its working fine.
But the problem is when they will click the next button go to next question, the time is resetting and loading from first.
Here my aspx code:

<script language="javascript" type="text/javascript"> var mins
var secs;
function cd() {
var tmin = document.getElementById("txtMin").value;
mins = tmin * m("1");
secs = 0 + s(":01");
redo();
}

function m(obj) {
for (var i = 0; i < obj.length; i++) {
if (obj.substring(i, i + 1) == ":")
break;
}
return (obj.substring(0, i));
}

function s(obj) {
for (var i = 0; i < obj.length; i++) {
if (obj.substring(i, i + 1) == ":")
break;
}
return (obj.substring(i + 1, obj.length));
}

function dis(mins, secs) {
var disp;
if (mins <= 9) {
disp = " 0";
} else {
disp = " ";
}
disp += mins + ":";
if (secs <= 9) {
disp += "0" + secs;
} else {
disp += secs;
}
return (disp);
}

function redo() {
secs--;
if (secs == -1) {
secs = 59;
mins--;
}
document.cd.disp.value = dis(mins, secs);
if ((mins == 0) && (secs == 0)) {
window.alert("Time is up. Press OK to continue.");
} else {
cd = setTimeout("redo()", 1000);
}
}

function init() {

cd();
}

window.onload = init;


</script>


<asp:TextBox ID="txtMin" Text="25" runat="server"> </asp:TextBox> <asp:UpdatePanel runat="server" ID="TimePanel" UpdateMode="Always"> <Triggers> </Triggers> <ContentTemplate> <input id="txt" readonly="true" type="text" value="10:00" border="0" name="disp" /> </ContentTemplate> </asp:UpdatePanel>


What I need is I want to call that init(); function only at the first time of page load, not at every post back.

Its very urgent. Pls solve my problem. My mail id is [email protected]


Thanks.

Answers (2)