Skip to content

Working with JavaScript

September 4, 2007

When you are working on JavaScript UI libraries, or any code that creates dynamic user-interface elements, there are 3 primary ways for clients to work with your JavaScript.

1. You can have your expect the client to provide you with the ID of the element to render in.
2. You can output the controls directly onto the page using some for of document.write().
3. You can have a server side control output the JavaScript for you.

Example of 1:

<script>
var tree;
function treeInit() {
tree = new YAHOO.widget.TreeView("treeDiv1");
var root = tree.getRoot();
var tmpNode = new YAHOO.widget.TextNode("mylabel1", root, false);
var tmpNode2 = new YAHOO.widget.TextNode("mylabel1-1", tmpNode, false);
tree.draw();
}
</script>

Example of 2: ActiveWidgets

<script>
// create ActiveWidgets component
var obj = new AW.UI.Button;
// set the display text
obj.setControlText("Click me");
// assign click event handler
obj.onControlClicked = function(){
this.setControlText("Hello World!");
};
// add component to the page
document.write(obj);
</script>

Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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: