Frameworks| Hibernate| Struts| JSF| JavaFX| Ajax| Spring| DOJO| JDO| iBatis| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Dojo Hello World 
 

In this tutorial, you will learn how to create a "Hello World" example in Dojo. Before creating any examples or applications you must be follow the its directory structure.

 

Dojo Hello World

                          

In this tutorial, you will learn how to create a "Hello World" example in Dojo. Before creating any examples or applications you must be follow the its directory structure.

Try Online: Hello World

Create a Button

The following example we are going to create a button "Hello World!". To create a button in dojo you need to a Button Widget that contains three visual states as: mouseOut, mouseOver and mouseDown. To follow the following steps for creating a dojo button widget:

<script type="text/javascript">
            // Load Dojo's code relating to widget managing functions
            dojo.require("dojo.widget.*");

            // Load Dojo's code relating to the Button widget
            dojo.require("dojo.widget.Button");
</script>

dojo.require("dojo.widget.*"): It instructs you to include the dojo widget (Not load all the widgets) for managing functions. 

dojo.require("dojo.widget.Button"): This line instructs you to load the Dojo button widget. If you don't include this line, the markup code for the button would not be evaluated by Dojo upon loading, resulting in a plain HTML button instead of what you expect.

Insert the following code into the  HTML body:

   <button dojoType="Button" widgetId="helloButton" onClick="helloPressed();">Hello World!</button>

The key attribute of this HTML element to notice is the dojoType attribute. This is responsible for instructing Dojo on how to process the element when the page is loading. In this case you will use a button element for the button that is used to input element - Dojo will work with either as long as the dojoType attribute is present.

widgetId="helloButton":  This is replaced with id="helloButton" without the functionality being affected - Dojo's widget system is smart enough to convert regular id attributes to widgetId's if no widgetId` attribute is explicitly named.

Connecting an Event to the Widget

When you click the command button then it doing something? We specify an onClick event handler for the given command button.

dojo.require("dojo.event.*");

Above code we use "dojo.event.*" that includes all events functionality of Dojo (But not all widgets). 

Following function that will called by the button when we clicked. After clicking the "helloPressed" method is called and it displays an alert message like: "Click on the Hello World Button". 

          function helloPressed()
      {
      alert('Click on the Hello World Button');
      }

Here is the code of program:

<html>

<head>
<title>button</title>
    <script type="text/javascript">
      dojo.require("dojo.event.*");
      dojo.require("dojo.widget.*");
      dojo.require("dojo.widget.Button");

      function helloPressed()
      {
      alert('Click on the Hello World Button');
      }

      function init()
      {
      var helloButton = dojo.widget.byId('helloButton');
      dojo.event.connect(helloButton, 'onClick', 'helloPressed')
      }

    dojo.addOnLoad(init);
    </script>


</head>

<body bgcolor="#FFFFCC">

<p align="center"><font size="6" color="#800000">Welcome to Roseindia Dojo Project</font></p>

<button dojoType="Button" widgetId="helloButton" onClick="helloPressed();">Hello World!</button>
<br>
    
</body>

</html>

Output of program:

After clicking the "Hello World!" command button, you get:

 

Try Online:

 

                          

» View all related tutorials
Related Tags: c dojo io accordion this ai container learn ear e il section in nt out j do s is ll

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

5 comments so far (
post your own) View All Comments Latest 10 Comments:

Hi,
Thanks for Excellent tutorial!
I have one question following code will also produce the same result with out using dojo.

<code>
<html>

<head>
<title>button</title>
<script type="text/javascript">
function helloPressed()
{
alert('Click on the Hello World Button');
}

</script>


</head>

<body bgcolor="#FFFFCC">

<p align="center"><font size="6" color="#800000">Welcome to Roseindia Dojo Project</font></p>

<button dojoType="Button" widgetId="helloButton" onClick="helloPressed();">Hello World!</button>
<br>

</body>

</html>
</code>

Posted by Vijay on Saturday, 01.31.09 @ 12:29pm | #84361

it works even when dojo.addOnLoad(init) is not called

Posted by ANANTHA KRISHNA PILLAI on Tuesday, 09.16.08 @ 14:52pm | #79830

it is really excellent and extrodinary......i am very thank full to rose india.here i want to discuss one doubt is...how it loads and reads the init() method.except this....the step by step example..is really ultimate

Posted by Ramana murthy koppula on Thursday, 05.15.08 @ 15:38pm | #60033

Excellent tutorial! please give some more examples which are commonly used in generating client side validations.

Posted by chandu on Thursday, 03.6.08 @ 18:58pm | #51711

Hi,

This is one of the best tutorial.

Thanks to the author. Please keep posting this type of tutorials.

Thanks
Ravi

Posted by Ravi on Tuesday, 02.12.08 @ 15:08pm | #48008

Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.