Unknown98 Posted December 5, 2010 Share Posted December 5, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/220741-javascript-popups-within-php-if-statement/ Share on other sites More sharing options...
RichardRotterdam Posted December 5, 2010 Share Posted December 5, 2010 I suggest you focus on this part as you describe first: 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. Search the web for javascript confirm box and let us know if you get stuck with your code. Quote Link to comment https://forums.phpfreaks.com/topic/220741-javascript-popups-within-php-if-statement/#findComment-1143242 Share on other sites More sharing options...
.josh Posted December 5, 2010 Share Posted December 5, 2010 you cannot mix php and javascript like that. php is a server-side language, it gets parsed on the server and after it is done, the results are output, sent to the browser. From there, your javascript will be executed, because javascript is a client-side language, parsed and executed on the client (in this case, the browser). As far as php (and your server) is concerned, javascript is just arbitrary text. Quote Link to comment https://forums.phpfreaks.com/topic/220741-javascript-popups-within-php-if-statement/#findComment-1143243 Share on other sites More sharing options...
Lautarox Posted December 5, 2010 Share Posted December 5, 2010 As Crayon Violent says, javascript is only executed on the browser, but you can output a javascript confirmation box as any other html content. You can create another php page to handle the the confirmation, but you can't start loading the php code and in a certain time stop it to ask for something, it loads, outputs and finishes. Quote Link to comment https://forums.phpfreaks.com/topic/220741-javascript-popups-within-php-if-statement/#findComment-1143265 Share on other sites More sharing options...
Unknown98 Posted December 7, 2010 Author Share Posted December 7, 2010 Ok, thanks. So I'd do something like if the statement is true, redirect to this new page. On the new page, I would have the confirm box. If they say yes, it continues with the code on the new page. If no, it redirects back to another page. If the statement is false overall, it just moves on. Would that work? Quote Link to comment https://forums.phpfreaks.com/topic/220741-javascript-popups-within-php-if-statement/#findComment-1143779 Share on other sites More sharing options...
Lautarox Posted December 7, 2010 Share Posted December 7, 2010 Yes, if you do this in separated pages it woul work. There's no need of javascript for what you are saying, just a form that will be submitted each time you click the submit button and it will be checked in the next page if what was inputted was correctly. (You don't need javascript unless you want to make something else than a submit button to change pages). It will be like a normal form. Quote Link to comment https://forums.phpfreaks.com/topic/220741-javascript-popups-within-php-if-statement/#findComment-1143951 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.