• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Stopping an IsDefined with Javascript

LEGEND ,
Dec 11, 2006 Dec 11, 2006

Copy link to clipboard

Copied

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
no?

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


TOPICS
Advanced techniques

Views

269

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 11, 2006 Dec 11, 2006

Copy link to clipboard

Copied

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
result.

onclick="return confirmForm()"

A couple of other observations:

The "language" attribute of <script> is deprecated. You should be using
the "type" attribute.
http://www.w3.org/TR/html4/interact/scripts.html#h-18.2.1

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.

--
Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 11, 2006 Dec 11, 2006

Copy link to clipboard

Copied

LATEST
I know it was a stretch posting it here, but you answered my question
perfectly. Appreciate it.


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation