Uncategorized

Why I love and hate JavaScript

2009.03.16 OaD #75 | Consumed by code

JavaScript is a powerful client side scripting language.  It allows developers to quickly add/remove functionality.  It can be dropped in or generated from code.  In WEB 2.0, JavaScript is the backbone of creating rich user environments.  It is quite the catch 22.  Oh how I love to hate and hate to love JavaScript.

JavaScript can pass some rudimentary tasks to the client so, as developers know, this can save processing cycles.  Sometimes it can actually add processing cycles, so it definitely depends.  Saving processing time allows application to run faster for the most part.  You don’t have to wait for a complete page cycle to do tasks ala 1998.  Basically, users are not patient nor should they be patient.  They are used to the Desktop world.  I feel JavaScript helps bridge that gap for users; sometime developers/designers go overboard.

Ease of Use

Love
Javascript is easy to use.  Compatible with any web programming language: Classic ASP, .NET, PHP, Ruby, JSP.  It integrates easily.  It is fairly lightweight and the syntax is not mind-blowing.

Hate
It is a little to easy to use and users can directly access things in your page.  It gives the user more control than what they know.  Look you can easily change the background of any page in the address bar.

javascript:document.bgColor = ‘#000000’;void(0);
^ Paste that into the address bar and press enter -> changes the background

This only touches the surface of what JavaScript can do.  It can get into your web app and change things around.  I use it for quick fixes on the fly or to try different things.  You can’t rely on JavaScript it will only cause you pain.  Can you trust the DOM?  No.

JavaScript is an interesting topic still it was once vogue, faded out, and then came back (with velocity).  I think at one point in JavaScript’s history it was somewhat confused for Java, but I don’t think that is currently valid.  There are so many great JavaScript libraries out there that enhance the UI and the total web experience.

They are even available from the Google API with no API Key which is an added bonus; unlimited connections to boot.  I don’t think a lot of these effects/plug-ins would be as robust or available if not for JavaScript libraries and the good old Goog.

I really don’t hate JavaScript, but I think it can be overused or used incorrectly (say for validation).  Sure it can help in notifying the end-user of validation issues; it should also be validated on the server side.  Web development is a many layered burrito.

Advertisements
Uncategorized

Adding Tooltips to Checkboxlist Items

checkbox-1 The CheckBoxList control in Microsoft ASP .NET 2.0 can be quite limiting in features.  You can set a tooltip for the overall control; we can say “HEY THIS IS A CHECKBOXLIST”, which is great if that somehow helps you.  The true power would be in adding a tooltip to each individual item in the checkboxlist.  It would be nice to databind the field like other ASP .NET 2.0 Controls, but again no such luck.

To add a Tooltip to each individual item you are going to have to loop through the control.  By setting the title attribute to whatever you want will give you the individual control to name each checkbox in the checkboxlist.  This can done be done when pulling items in or on the case of a control firing.  Whatever works for you.

[lang=”vb”]
‘ Loop through CheckBoxList and set tooltip to checked if selected
For Each item As ListItem In CheckBoxList1.Items
If item.Selected Then
item.Attributes(“title”) = “CHECKED”
End If
Next
[/lang]

This is really just a quick and dirty way to add tooltips to checkboxlist items.  If you are already pulling in jQuery or some other library I would say use one of the many Tooltip plugins out there.  If you are not using any Javascript libraries this can be a quick way to help achieve a goal.  I’m not sure if this will work in Firefox, but if you are going for crossbrowser definitely check out a Javascript library.