0

hello to every one

I have following code and it simple example of timer ..and it should appear alert after 3 seconds but this does not happening .. any help

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Paper.aspx.cs" Inherits="JQueryAjax.Paper" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript">

    function myFunction()
{
setTimeout(function(){alert("Hello")},3000);
}

    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <p>Click the button to wait 3 seconds, then alert "Hello".</p>
<button onclick="myFunction()">Try it</button>

    </div>
    </form>
</body>
</html>
3
Contributors
4
Replies
40
Views
4 Years
Discussion Span
Last Post by radhakrishna.p
0

hai erum,

i too surprised by seeing this kind of requirement

its working for the click event of button like this format

<input type="button" name="" value="Try it" onclick="myFunction()"/>

than this

<button onclick="myFunction()">Try it</button>

i dont know the reason exactly but i think this might be html version problem

we will wait for proper reason from anyone of experts here

Edited by radhakrishna.p: giving clarity on the solution

0

Erum,

When the button is clicked your function will be called and the timer started. Just a few milliseconds after the call to setTimeout() your function will exit and the form is posted back to the server. When this happens you'll loose any environment or state. The timeout you set will no longer exist.

If you prevent the form from being posted back, you should find the timeout works fine. On line 18, try something like...

<form id="form1" runat="server" onsubmit="return false">

Edited by LaxLoafer

0

LaxLoafer your suggestion worked out ... thanks

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.