Jump to content

alert dialog that passes value to execute function in php


Joseph_J

Recommended Posts

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

 

 

 

 

 

 

 

 

 

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.


$('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!";
}
}
});


Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.