...

View Full Version : Confirm box not working



Harry
12-24-2003, 08:17 PM
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>

Dennis
12-24-2003, 08:20 PM
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()'>

fredmv
12-24-2003, 08:24 PM
First off, all you should need is this:
function confirmDelete()
{
return confirm('Are you sure you want to delete this description?');
}Second, your onsubmit event handler should look like this:
onsubmit="return confirmDelete();"

Dennis
12-24-2003, 08:26 PM
yes... i didn't think on this way... than you can also do something on line...

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

:)

fredmv
12-24-2003, 08:30 PM
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.

Dennis
12-24-2003, 08:35 PM
sure :-)

fredmv
12-24-2003, 08:40 PM
I'm not sure if you even understand the concept behind this based on the fact that your original code looked like this:
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.

Dennis
12-24-2003, 08:46 PM
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 :D

Harry
12-24-2003, 08:56 PM
Thanks a lot guys, you always come through for me when I need it most.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum