SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard nofel's Avatar
    Join Date
    Aug 2007
    Location
    Earth
    Posts
    1,766
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    how to initiate a query afterJS confirm

    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?
    All those who wander aren't lost.

  2. #2
    SitePoint Wizard nofel's Avatar
    Join Date
    Aug 2007
    Location
    Earth
    Posts
    1,766
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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
    All those who wander aren't lost.

  3. #3
    SitePoint Wizard bronze trophy Immerse's Avatar
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    1,661
    Mentioned
    7 Post(s)
    Tagged
    1 Thread(s)
    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.

  4. #4
    SitePoint Wizard nofel's Avatar
    Join Date
    Aug 2007
    Location
    Earth
    Posts
    1,766
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    that is what i m confused. i donno what to pass in if parameters, like
    Code:
    if(true){
    do this
    }else{
    do this
    }
    what parameter shld i pass in ()
    All those who wander aren't lost.

  5. #5
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Try this:

    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.


Bookmarks

Posting Permissions

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