0

I have a confirm box and redirect to an action but it is not working..

<script type="text/javascript">


  function quitProgram()
    {
        var answer = confirm("Are you sure you want to quit your current program?");
        if (answer)
            window.location("http://www.google.com");
        else
            window.location("http://www.yahoo.com");
     }
    </script>

Html Code -

<input style="float:right;" type="submit" value="Quit Program" id="QuitProgram" onclick="quitProgram()" />

But the redirect never happens...can anyone help me with this..ultimately what i want to do is redirect to an action based on user response...it would be great if anyone lets me know the best way i should do this?

3 Answers 3

4

window.location is a property not a method:

if (answer)
    window.location = "http://www.google.com";
else
    window.location = "http://www.yahoo.com";
Sign up to request clarification or add additional context in comments.

2 Comments

Nice.. it's like a brain teaser sometimes, when something looks right but is the totally wrong syntax.
ya...my bad...and thanks Jeff...actually that submit was a problem..it worked when i changed it to button..
2

Stuart identified one problem with the code posted in the question. One more thing you'll have to do is change the input element's type from "submit" to "button", or the submit will cause a post that will override the redirect.

Comments

0

I am not sure but try this

function quitProgram()
{
    var answer = return confirm("Are you sure you want to quit your current program?");
    if (answer)
        window.location("http://www.google.com");
    else
        window.location("http://www.yahoo.com");
 }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.