Javascript confirm() not working
-
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: -
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: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.
-
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: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.
-
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.
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