Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 6 of 6
  1. #1
    Member Unknown98's Avatar
    Join Date
    May 2008
    Location
    Houston
    Posts
    46
    Member #
    16866
    How would I implement a javascript confirm box within a PHP if statment? I have an if statement, and if it is true, I want a confirm box to pop up asking the user if they would like continue, or cancel the operation and go back. If they click yes, it should continue with the rest of the script. If no, it will simpily redirect back to the first page. If the if statement is false all together, it just skips that step and moves on to the next else statment. I have the entire php script working, it's just the confirm box I want to implement so the user doesn't unexpectedly have something happen they don't want to happen. Otherwise, the script will just continue without asking the user anything, and they might not want that.

  2.  

  3. #2
    Senior Member Dorky's Avatar
    Join Date
    Jun 2009
    Location
    Destin Florida
    Posts
    1,430
    Member #
    19103
    Liked
    4 times
    The XMLHttpRequest Object an xml http request should do the trick.

    while($get_it !== true){ continue; }

  4. #3
    Member Unknown98's Avatar
    Join Date
    May 2008
    Location
    Houston
    Posts
    46
    Member #
    16866
    Hmm, ok thanks. I'll look into those. Never used them before.

  5. #4
    Senior Member paintingtheweb's Avatar
    Join Date
    Jul 2007
    Location
    Las Vegas
    Posts
    128
    Member #
    15503
    I think what you're asking for here actually can't be done that way. Since PHP and JS are actually processed at different times (server-side vs client-side) you can't actually intermingle functionality of the two that way. What Dorky was referring to was using ajax to do what you're trying to do which is basically javascript calling the php when it needs to from a separate page. If you're using jquery, it has a simplified $.ajax function that would probably do what you're wanting pretty well. Take a look at that and post back with any questions.

  6. #5
    Senior Member Dorky's Avatar
    Join Date
    Jun 2009
    Location
    Destin Florida
    Posts
    1,430
    Member #
    19103
    Liked
    4 times
    The XMLHttpRequest Object

    The XMLHttpRequest object is used to exchange data with a server behind the scenes.
    The XMLHttpRequest object is a developer's dream, because you can:

    • Update a web page without reloading the page
    • Request data from a server after the page has loaded
    • Receive data from a server after the page has loaded
    • Send data to a server in the background

    The XMLHttpRequest Object

    you can do this with javascript. just send the data to a file with the http request vice versa. you can google for examples ll over the net.

    AJAX Introduction as you can see ajax that you refer to is javascript, xml, and php. ajax is not it's own language. jquery is not required in ajax, just another way of going about it.

    while($get_it !== true){ continue; }

  7. #6
    Member Unknown98's Avatar
    Join Date
    May 2008
    Location
    Houston
    Posts
    46
    Member #
    16866
    Yes, I just made another page so that if the statement is true, it redirects to that page. The new page then has a javascript box that comes up, and allows the user to continue or go back. Thanks for the help!


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 10:31 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com