hi, i am creating a script that will confirm a person when they click delete. they are prompted with confirm from JS. how can i use that confirm yes from user,into initiating of a delete query?
i know, JS is client side and PHP is server side. but how can i prompt a user for confirmation before executing delete query? depending on what he clicks, will be deleted or not
Well, the easiest way is to check the returned value from the confirm() , and if it's null or false, don't actually send the user to the page where the record is deleted (or don't submit the form, if it's a form).
If the result of the confirm() is true (which will happen by pressing 'OK'), then you can go ahead and send the user to the page on which the record is deleted.
that is what i m confused. i donno what to pass in if parameters, like
what parameter shld i pass in ()
Your html form is sent whatever happens.
If the user has JS turned on then your JS must check the return value of the confirm box and then submit your form programmatically.
If JS is turned off, your form should ideally submit regardless, except the double check with the confirm box will not have appeared.
If that is what you want, you are facing a JS coding problem - little/nothing to do with PHP at all.
You can do similar just using PHP and not relying on JS: Send an extra request to the server.
1 Form showing a delete button:
submits to a page which asks:
2 Are you sure you want to delete?
submits to a page which:
3 Deletes the record, then shows a helpful message or re-routes back into the workflow at the appropriate place.
There is probably another way to do this using Ajax.