Monday, June 01, 2009

It's been a little while

So with all of the fancy iPhone, AppEngine, GWT, Android development I've been involved with I was on the job the other day and someone asked me how to do something in Javascript.  Her problem was a tricky one but it basically built upon a very simple foundation.  When a user selected something she needed some text and a style to change.  I knew immediately how to do it but the syntax escaped me for a bit so I thought I'd stick it out here for the next time I needed it.

The problem is pretty simple click a button change some text and the color of the text.  So here is my very simple solution.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
   <title> Switch </title>
      <script type="text/javascript">
         function change()
            var styleClass = 'required';
            var textValue = 'Else'
            if (document.getElementById('sigDate').className == 'required')
      <style type="text/css">
            color: RED;
            color: BLUE;
      <input type="button" value="Switch" onclick="change()" />
      <div id="sigDate" class="standard">

Like I said a very simple solution to build a very complex solution upon.



No comments: