Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jan 2004
    Location
    Port Huron, MI, U.S.A.
    Posts
    280
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Form reset confirm problem

    I have a small form where I am using a cofirm on the reset button click. For some reason though, the confirm always acts as true. How can I fix that (I already tried if (confirm()) ). Also, how can you make it so you cancel a button click or event like "reset()" (see the *)?

    Code:
    <script>
    <!--hide
    function CLEARIT() {
    var y=confirm('Are you sure you want to clear\?');
    if (y='true') {document.g.reset()};
    else { * };
    	}
    //-->
    </script>
    Last edited by Bobo; 03-18-2004 at 02:31 AM.

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    <input type="reset" value="Reset" onclick="return confirm('Are you sure you want to clear?');"/>
    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”

  • #3
    Regular Coder
    Join Date
    Mar 2004
    Posts
    138
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yeah, that's the easy way to do it. The reason yours wasn't working is because you just have to put if (y). y is either true or false and the if loop works on whether or not the expression is true, so you don't have to put if (y='true'). The reason that didn't work is because it was assigning the value 'true' to y and there was nothing to be false. You have to use == without quotes around true. And you don't need an else in this case. But yeah just do it the easy way. I was just telling you this for future reference.

  • #4
    Regular Coder
    Join Date
    Jan 2004
    Location
    Port Huron, MI, U.S.A.
    Posts
    280
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile

    Thanks a ton!!


  •  

    Posting Permissions

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