Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help using javascript confirm() function with php

Status
Not open for further replies.

buspass

Programmer
Feb 2, 2003
29
GB
How can I use a javascript confirm() function when asking a user if he is sure he wants to delete a record?

So far i've tried a variation of the following:

echo (&quot;<script language =\&quot;JavaScript\&quot;>&quot;);
echo (&quot;var del=&quot;);
echo(&quot;confirm(\&quot;Really\&quot;);&quot;);
echo(&quot;if (del)&quot;);
{$rs=delete_record(blah.....);
}
echo(&quot;else&quot;);
{
echo(&quot;alert(\&quot;Delete cancelled\&quot;);&quot;);
}
echo(&quot;</script>&quot;);

Any help or suggestions welcomed
 
$rs=delete_record(blah....);

looks suspiciously like a PHP statement to me.... you can't mix these two like that.

Javascript runs client side, PHP runs serverside... keep this in mind.

-Rob
 
I have found a simple solution which works fine.

I add:
onclick=\&quot;javascript:return confirm('Are you sure you want to delete your details? Click OK to confirm, or Cancel to abort.')\&quot;

after my submit button. If user clicks OK it continues to the delete page, else does nothing.

 
I need exactly the same thing here. But sorry I don't know anything about Javascript, so i don't know how to call onclick. Furthermore, instead of submit button, what i have is a delete image, if user clicks on the image, it calls another page which deletes the record, like:

echo &quot; <A href=\&quot;delete.php?pid=&quot;.$row[&quot;pid&quot;].&quot;\&quot;><img border=0 src=pics\deletebutton.gif ></a>\n&quot;;

on delete.php page:

$sqlquery = &quot;delete from project where pid='&quot;.$pid.&quot;'&quot;;
$queryresult = mysql_query($sqlquery)

Deleting records works just fine, now i need a confirmation pop up window in Javascript, what should i do?

Thanks so much,
Lea
 
Sorry to bother you guys, i just figured it out. I simply put <A href=\&quot;delete.php?pid=&quot;.$row[&quot;pid&quot;].&quot;\&quot; onClick=\&quot;javascript:return confirm('Are you sure you want to delete your record?)\&quot;></a> and it worked.

thanks anyways.

Lea
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top