alert is not appearing-VBForums
Results 1 to 6 of 6

Thread: alert is not appearing

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2007
    Location
    Karachi
    Posts
    551

    alert is not appearing

    hello to every one

    I have following code and it simple example of timer

    Code:
    <%@ 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>
    and it should appear alert after 3 seconds but this does not happening .. any help
    There is no achievement without goals

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    31,256

    Re: alert is not appearing

    I got it to work.... by removing the form tag... which is what I expected... the presence of a form tag cause the browser to do a form send, either by GET (default) or POST ... so what's happening is that you're GETting the form, causing it to reload/refresh... so the timer never gets a chance to run.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3
    March 2015 Winner kfcSmitty's Avatar
    Join Date
    May 2005
    Location
    Kingston, Ontario
    Posts
    2,125

    Re: alert is not appearing

    Quote Originally Posted by techgnome View Post
    I got it to work.... by removing the form tag... which is what I expected... the presence of a form tag cause the browser to do a form send, either by GET (default) or POST ... so what's happening is that you're GETting the form, causing it to reload/refresh... so the timer never gets a chance to run.

    -tg
    Correct. If you want to use a button in a form tag, use <input type="button", not the button element. As using the button element can submit a form: http://www.w3schools.com/tags/tag_button.asp

  4. #4
    Frenzied Member tr333's Avatar
    Join Date
    Nov 2004
    Location
    /dev/st0
    Posts
    1,606

    Re: alert is not appearing

    You can also just do <button type="button">click me</button> to prevent form submission with a button tag.

    https://developer.mozilla.org/en-US/...Element/button
    CSS layout comes in to the 21st century with flexbox!
    Just another Perl hacker,

  5. #5
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    CT
    Posts
    17,512

    Re: alert is not appearing

    I am wondering - can you also do it by having a RETURN FALSE somewhere in that function to stop the event from propagating? Just curious...

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    31,256

    Re: alert is not appearing

    if the myFunction returns False... then you would have to call it like this:
    <button onclick="return myFunction();">Try it</button>

    you could also do this (and not modify the myFunction):
    <button onclick="myFunction(); return false;">Try it</button>

    I've done that before... but it would also depend on whether the form was just a container for the button (and if that's the case it should be removed to be semantically right)

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.