/    Sign up×
Community /Pin to ProfileBookmark

Delete confirm box assistance needed

Hi!

I have read countless pages around the net and the ones I can find here, but I still can not get a javascript delete confirm box to work correctly for my site written in PHP. I have tried everything I can find. Here is my scenario:

I am finishing a script which queries the database for exceptions. It then lists various information about that record and offers a delete button to delete it at the end. Here is that code:

[code]
echo ‘<td>’, ‘<a href=”database_check.php?action=delete_products&ref=5&products_id=’.$products_id.'” onclick=”confirmDelete();”>’,'<img src=”includes/languages/english/images/buttons/button_delete.gif” border=”0″ alt=”Click to delete record”></a>’;
[/code]

As you see, I am passing 3 variables in this url. I should mention that this code is on the same page where the case “delete_products” is.. and all of that works great. The confirmDelete() code refered to above is this:

[code]
<script>
function confirmDelete()
{
var confirmMe= confirm(“Do you really want to Delete??”);
if (confirmMe== true)
{
return true
}
else
{
return false
}
}
</script>
[/code]

The confirm box comes up alright.. but.. makes no difference if I click yes or no, it still deletes the record.

By the way, this is what is in the delete_products case:

[code]
case ‘delete_products’:
tep_db_query(“delete from testing_products where products_id = ‘” . $HTTP_GET_VARS[‘products_id’] . “‘”);
tep_db_query(“delete from testing_products_description where products_id = ‘” . $HTTP_GET_VARS[‘products_id’] . “‘”);
tep_db_query(“delete from testing_products_to_categories where products_id = ‘” . $HTTP_GET_VARS[‘products_id’] . “‘”);
$action = $ref;
}
break;
[/code]

That deletes the record chosen and sends the user right back to the case they came from, thereby refreshing the results if they have more deletions to make. But.. in my case… how do i get this from stopping the delete from happening if the user chooses not to? I’m really not good with javascript at all.. but.. very literate in other languages.

Any help would be appreciated,

Iceman

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@KorApr 14.2008 — you Javascript function returns a Boolean, but you should also return a Boolean within the onclick event handler, in order to block the HTML href action. Thus:
<i>
</i>onclick="[B][COLOR="Blue"]return[/COLOR][/B] confirmDelete();"


A note:

You must specify the type of the script:
<i>
</i>&lt;script [COLOR="Blue"]type="text/javascript"[/COLOR]&gt;


Also: simplify the code:
<i>
</i>function confirmDelete(){
return confirm("Do you really want to Delete??");
}

as the confirm returns anyway a Boolean
Copy linkTweet thisAlerts:
@ohiomanauthorApr 14.2008 — Well i'll be darned! It worked like it was made for it. I'll tell ya.. if i were to have ever figured that thing out in my life... i would have been an old man!!! I really appreciate the fast help from here just now. Looks like you javascript folks around here really know your stuff!

Much thanks,

Iceman ?
×

Success!

Help @ohioman spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...