Joseph_J Posted October 2, 2013 Share Posted October 2, 2013 Hello, Thank you in advance for your time! I want to have an if(x!=y) statement that prompts a user to select continue or cancel. If (x!=y) { Prompt user to confirm (Continue/Cancel) } If (continue =true) { continue } else { allow user to fix mistake } Note: I am a total noob and not familiar with jscript or ajax and will need a description of how to implement the javascript or the ajax on the site. Thanks again. Joseph Quote Link to comment https://forums.phpfreaks.com/topic/282627-alert-dialog-that-passes-value-to-execute-function-in-php/ Share on other sites More sharing options...
codefossa Posted October 2, 2013 Share Posted October 2, 2013 I'm not really sure what you want to do. This would basically follow your pseudo code as far as I can tell. function ready() { function runTest() { var x = "that", y = prompt("Type anything but that!"); if (x != y) { if (confirm("Do you wish to continue?")) { alert("Let's go!"); return true; } else return runTest(); } return false; } if (runTest()) alert("We're gonna keep going."); else alert("Let's stop."); } window.addEventListener("load", ready, false); So, if you wanted to load a function in PHP, it would need a page you can call, then JS will grab the output of the function. I would suggest using jQuery to make this easier. Something like this maybe? $(document).ready(function() { function runTest() { var x = "that", y = prompt("Type anything but that!"); if (x != y) { if (confirm("Do you wish to continue?")) return true; else return runTest(); } return false; } if (runTest()) { var div = $(document.createElement("div")).load("/mypage.php"); } else alert("We've stopped .."); }); All of this is untested, but it's just kind'a to give an idea. I'm not really sure what you want to accomplish, so hopefully this helps. Quote Link to comment https://forums.phpfreaks.com/topic/282627-alert-dialog-that-passes-value-to-execute-function-in-php/#findComment-1452208 Share on other sites More sharing options...
Joseph_J Posted October 3, 2013 Author Share Posted October 3, 2013 (edited) Where do I place the function runTest() ? Is that a <script> call? Edited October 3, 2013 by Joseph_J Quote Link to comment https://forums.phpfreaks.com/topic/282627-alert-dialog-that-passes-value-to-execute-function-in-php/#findComment-1452395 Share on other sites More sharing options...
lilmer Posted October 8, 2013 Share Posted October 8, 2013 $('button').click(function(){ var value = $('input').val(); if(value != null){ var r=confirm("Do you want to continue?"); if (r==true) { x="You pressed OK!"; } else { x="You pressed Cancel!"; } } }); Quote Link to comment https://forums.phpfreaks.com/topic/282627-alert-dialog-that-passes-value-to-execute-function-in-php/#findComment-1453032 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.