2 Replies Latest reply on Dec 11, 2006 7:55 AM by Newsgroup_User

    Stopping an IsDefined with Javascript

    Level 7
      I have my site set so when the user clicks the button it triggers a
      IsDefined block of code to execute. I would like to set up a javascript
      functiont to pause the event and ask if they want to continue or not. If so,
      it continues normally, but if not, it will stop the execution.

      I have the button set with an onClick event that calls the javascript
      function for a pop up confirmation. How can I stop the event if they click

      <script language="javascript">
      function confirmForm() {
      if (confirm("Are you sure you want to regenerate the student ids?"))
      return true;
      alert("ID's have not been regenerated.")
      return false;

        • 1. Re: Stopping an IsDefined with Javascript
          Level 7
          Hi Wally.
          Firstly: this is a ColdFusion forum, as you know. However you're asking a
          Javascript question... this is not really the best place to be asking such
          things, for dual reasons of "appropriateness" and "likelihood to get
          answers (depending on the complexity of the question)".

          But anyway, what you need to do is to tell the event handler to return its

          onclick="return confirmForm()"

          A couple of other observations:

          The "language" attribute of <script> is deprecated. You should be using
          the "type" attribute.

          Also I think you might want to put curly braces around you "else" block in
          your function. Without curly braces, only the ONE subsequent instruction
          is considered the ELSE option. I suspect the return statement is also
          supposed to be in there.

          As a rule of thumb: ALWAYS use curly braces around logic blocks, as it
          makes your intent clearer, and prevents accidents like this.

          • 2. Re: Stopping an IsDefined with Javascript
            Level 7
            I know it was a stretch posting it here, but you answered my question
            perfectly. Appreciate it.