Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Jul 2003
    Location
    Houston, Texas
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Confirm box not working

    I have a form where a user can delete a row in a table. I am using the javascript confirm dialogue box to ask the user to confirm the delete. However, regardless of the choice they select, the form is submitted. Here is my code. Can someone tell where I missed the boat on this one?

    Thank you

    <form name='desc_maint' action='aud_update_desc.php' method='post' onsubmit='confirmDelete()'>

    <script>
    function confirmDelete(){
    var agree=confirm("Are you sure you want to delete this description?");
    if(agree){
    return true;
    }
    else
    {
    return false;
    }
    }
    </script>
    Beyond a critical point within a finite space, freedom diminishes as numbers increase. ...The human question is not how many can possibly survive within the system, but what kind of existence is possible for those who do survive."

  • #2
    New Coder
    Join Date
    Dec 2003
    Location
    Soraga, Trentino, Italy
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    try doing so...


    <script>
    function confirmDelete(){
    if(confirm("Are you sure you want to delete this description?"))return true;
    else return false
    }
    </script>


    and...

    <form name='desc_maint' action='aud_update_desc.php' method='post' onSubmit='return confirmDelete()'>

  • #3
    Regular Coder
    Join Date
    Jul 2003
    Location
    Massachusetts
    Posts
    472
    Thanks
    0
    Thanked 0 Times in 0 Posts
    First off, all you should need is this:
    Code:
    function confirmDelete()
    {
    	return confirm('Are you sure you want to delete this description?');
    }
    Second, your onsubmit event handler should look like this:
    Code:
    onsubmit="return confirmDelete();"

  • #4
    New Coder
    Join Date
    Dec 2003
    Location
    Soraga, Trentino, Italy
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yes... i didn't think on this way... than you can also do something on line...

    <form onSubmit="return confirm('Are you sure ecc...')">


  • #5
    Regular Coder
    Join Date
    Jul 2003
    Location
    Massachusetts
    Posts
    472
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Either way should work. If only the confirmation is needed, I would've done it the way you had suggested, but if more code is needed than just the confirmation I suppose a function would make more sense.

  • #6
    New Coder
    Join Date
    Dec 2003
    Location
    Soraga, Trentino, Italy
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    sure :-)

  • #7
    Regular Coder
    Join Date
    Jul 2003
    Location
    Massachusetts
    Posts
    472
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm not sure if you even understand the concept behind this based on the fact that your original code looked like this:
    Code:
    function confirmDelete(){
    if(confirm("Are you sure you want to delete this description?"))return true;
    else return false
    }
    The fact of the matter here is that the confirm method returns Boolean value based on which option the user chooses. This means that an if/else block isn't needed if all that you're doing within each one is returning a Boolean value (only the function itself would be needed). Moreover, if any further validation needs to be done (another element has a certain value, for example), a function would make the most sense if used on multiple forms and would result in more modular code.
    Last edited by fredmv; 12-27-2003 at 06:21 AM.

  • #8
    New Coder
    Join Date
    Dec 2003
    Location
    Soraga, Trentino, Italy
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Dont worry... i understood my mistake, i wrote so fast :d

    it's only that i'm a young italian and i learn english... then i dont understand the whole 3d

  • #9
    New Coder
    Join Date
    Jul 2003
    Location
    Houston, Texas
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks a lot guys, you always come through for me when I need it most.
    Beyond a critical point within a finite space, freedom diminishes as numbers increase. ...The human question is not how many can possibly survive within the system, but what kind of existence is possible for those who do survive."


  •  

    Posting Permissions

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