www.webdeveloper.com
Results 1 to 6 of 6

Thread: i need help in confirm()

  1. #1
    Join Date
    Apr 2011
    Posts
    67

    i need help in confirm()

    how can i stop validating a value if i press the cancel button in confirm()..

    because in my code if i press the cancel button it still passes a value

  2. #2
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,330
    See the confirm box section of:
    http://www.w3schools.com/js/js_popup.asp

    If that does not help, show some code.

  3. #3
    Join Date
    Mar 2011
    Posts
    65
    As far as I remember you'll need a:

    onclick="return confirm("Text");"

    without the return it won't work!

    And if the above code still does not work, try this:

    onclick="return confirm("Text"); return false;"

    One of the two is 100% correct!

  4. #4
    Join Date
    Apr 2011
    Posts
    67
    hmm i tried different things and yet i still didnt get the output
    i have php code in my javascript i sorry if i posted it in the wrong section..
    because my only problem is the prompt confirm()

    here's the code:

    <script type="text/javascript">
    r = confirm("test");
    function ask(){
    if(r==true){
    return true
    }
    else if(r==false) {
    return false
    }
    }
    </script>

    <form method="GET" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>">
    //assume that there's a php code

    <input type="submit" name="submit" value="send" onclick="ask()">
    </form>

    @captainsessa i tried your suggestion but it didnt work..

    i still passed a value even i clicked the cancel button..

    i know whats the problem.. i used the input type="submit" instead of input type="button"

    but the only way to pass a value is to use submit in the input type..

  5. #5
    Join Date
    Mar 2011
    Posts
    65
    Actually the method SHOULD work afaik.. but here's another solution:

    Don't use a submit button, use type="button" and submit the form with javascript with form.submit if your confirm() thingy returns true

  6. #6
    Join Date
    Apr 2011
    Posts
    67
    i did it!

    <script type="text/javascript">

    function ask(){
    r=confirm("what");

    if(r==true){
    document.forms["myform"].submit();
    return true
    }
    else{
    return false
    }

    }
    </script>

    <form method="GET" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" id="myform">

    </form>

    <input type="button" name="submit" value="send" onclick="ask()">

    but the problem is.. it only works if i put the input type outside the form.. kinda suxx... if you put the input type inside the form it does pop the prompt but.. there's no validation actions happened if you clicked the ok and cancel.. how to fix it??
    Last edited by ballball; 10-05-2011 at 10:28 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles