Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Javascript confirm() not working

Javascript confirm() not working

Scheduled Pinned Locked Moved Web Development
javascripthtmlsysadmintoolsquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    chubbysilk
    wrote on last edited by
    #1

    Hello, When the user pushes a button, I would like to pop up a dialog box which asks them if they would like to continue or not. It the user chooses to continue, then the code on the server will run. I attempted to do this using the Javascript confirm() method. Here is my script: function ConfirmDelete() { var msg = "Are you sure you want to delete the account?"; if(confirm(msg)) { <%DeleteAccount();%> } } Here is the html: For some reason, the code in the ConfirmDelete function is being called immediately when the page loads (this includes the DeleteAccount server code), instead of just when the button is pushed. Is there something wrong with my code? Or, is there a different way to do this? Thanks, RC

    J 2 Replies Last reply
    0
    • C chubbysilk

      Hello, When the user pushes a button, I would like to pop up a dialog box which asks them if they would like to continue or not. It the user chooses to continue, then the code on the server will run. I attempted to do this using the Javascript confirm() method. Here is my script: function ConfirmDelete() { var msg = "Are you sure you want to delete the account?"; if(confirm(msg)) { <%DeleteAccount();%> } } Here is the html: For some reason, the code in the ConfirmDelete function is being called immediately when the page loads (this includes the DeleteAccount server code), instead of just when the button is pushed. Is there something wrong with my code? Or, is there a different way to do this? Thanks, RC

      J Offline
      J Offline
      John Kuhn
      wrote on last edited by
      #2

      If I put the following into <script> tags in the <head> section of a plain-ol' vanilla HTML page, like so:

      <script>
      function ConfirmDelete()
      {
      var msg = "Are you sure you want to delete the account?";
      if(confirm(msg))
      {
      // do something
      }
      }
      </script>

      and the following in a plain HTML button:

      <input type="button" id="blah" onClick="ConfirmDelete();" name="blah" value="Click">

      ...it works just fine, at least with IE6.x on W2K. What a piece of work is man, how noble in reason, how infinite in faculties, in form and moving how express and admirable . . . and yet to me, what is this quintessence of dust? -- Hamlet, Act II, Scene ii.

      1 Reply Last reply
      0
      • C chubbysilk

        Hello, When the user pushes a button, I would like to pop up a dialog box which asks them if they would like to continue or not. It the user chooses to continue, then the code on the server will run. I attempted to do this using the Javascript confirm() method. Here is my script: function ConfirmDelete() { var msg = "Are you sure you want to delete the account?"; if(confirm(msg)) { <%DeleteAccount();%> } } Here is the html: For some reason, the code in the ConfirmDelete function is being called immediately when the page loads (this includes the DeleteAccount server code), instead of just when the button is pushed. Is there something wrong with my code? Or, is there a different way to do this? Thanks, RC

        J Offline
        J Offline
        John Kuhn
        wrote on last edited by
        #3

        By the way, the only way you can execute code stored in a server-side ASP function from a client-side JavaScript is to make the JavaScript post back to the server, either by posting a form or navigating to a URL with a query string. What a piece of work is man, how noble in reason, how infinite in faculties, in form and moving how express and admirable . . . and yet to me, what is this quintessence of dust? -- Hamlet, Act II, Scene ii.

        C 1 Reply Last reply
        0
        • J John Kuhn

          By the way, the only way you can execute code stored in a server-side ASP function from a client-side JavaScript is to make the JavaScript post back to the server, either by posting a form or navigating to a URL with a query string. What a piece of work is man, how noble in reason, how infinite in faculties, in form and moving how express and admirable . . . and yet to me, what is this quintessence of dust? -- Hamlet, Act II, Scene ii.

          C Offline
          C Offline
          chubbysilk
          wrote on last edited by
          #4

          I think the reason my code was not working is because I was attempting to run server script from the client in the <%DeleteAccount()%> line of the code. I found a different way to make it work using the javascript doPostBack function. Thanks for your input! RC

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups