Skip navigation

Dojo’s stopEvent method is a crossbrowser compatible way to stop further event bubbling when you want to take charge and control what happens manually. For example if you add an onclick event to an anchor and don’t want the browser to go the page specified in the elements href attribute, you can use the stopEvent method to prevent it from happening. You can also prevent also other many things, including button submits and the checking or unchecking of checkboxes. However, there’s a bug here! If you do use stopEvent to stop a checkbox toggle, you can’t set it manually either! Copy and paste this code and save it in an .html file and then open it up in a browser to see for yourself (the script tag points to a version of dojo hosted by Google):

<SCRIPT TYPE="text/javascript" SRC=""></SCRIPT>
<title>Script checkbox test thingy</title>
<h1>Check this box</h1>
<div id="container">
<input type="checkbox" id="cb" />
<label for="cb">Check it</label>
<script type="text/javascript">
dojo.byId("cb").checked = true;

There is a solution however! Use setTimeout with a wait time of 0 to attempt to check the box, and it will work!

window.setTimeout(function(){ dojo.byId("cb").checked = true;},0);

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: