Jump to content

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


This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.