DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Very Simple Script Using Dojo Widget And I/O

10.17.2006
| 6932 views |
  • submit to reddit
        <a href="http://dojotoolkit.org/">Dojo</a> is a Java Script toolkit. This is a minimal HTML page which uses a widget and talks to the server. This is based on the Dojo tutorial at <a href="http://dojo.jot.com/WikiHome/Tutorials/HelloWorld">JotSpot</a>.

<html>
<head>
  <title>Dojo: Hello World!</title>

  <script type="text/javascript" src="/js/dojo/dojo.js"></script>

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

    function helloPressed()
    {
        dojo.io.bind({
                       url: '/cgi-bin/HelloWorldResponsePOST.rb',
                       handler: helloCallback,
                       formNode: dojo.byId('myForm')
                    });
    }

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

    function errorCallback(type, error)
    {
        alert(error)
    }

    function helloCallback(type, data, evt)
    {
      if (type == 'error')
        alert('Error when retrieving data from the server!');
      else
        alert(data);
    }

    dojo.addOnLoad(init);
  </script>
</head>

<body>
  <button dojoType="Button" widgetId="helloButton">Hello World!</button>
  <br>

  <form id="myForm" method="POST">
    Please enter your name: <input type="text" name="name">
  </form>

</body>
</html>