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()

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


Recommended Answers

All 4 Replies

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


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">

LaxLoafer your suggestion worked out ... thanks

please mark this thread as solved if you got answer

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.