Blog Home  Sign In RSS 2.0 Atom 1.0 CDF  

  def Softwaremaker() :
         return "William Tay", "<Challenging Conventions />"

  knownType_Serialize, about = Softwaremaker()
 

 Monday, December 26, 2005

One of the things that I thought <Input TYPE=radio> had always lacked is that it only allows it to be specified as part of only ONE group - which is dictated by the NAME attribute.

Therefore, with this code


<INPUT TYPE=radio NAME=names VALUE=1>William Tay
<INPUT TYPE=radio NAME=names VALUE=2>William Gates
<INPUT TYPE=radio NAME=names VALUE=3>William Tell 
I can do this: William Tay William Gates William Tell

However, if I wanted something with a 2-dimensional twist to it such as something like this:


Please Vote your Favourite Topics via a Preference Gauge

  Order of Preferences
Topic 1 1 2 3
Topic 2 1 2 3
Topic 3 1 2 3


I will be stuck somewhere in between because while I can select my order of Preferences (in terms of 1, 2, 3) for any of those topics, I cannot prevent other uses from selecting a Preference 1 for more than 1 topic. This kinda distorts the voting statistics as someone may vote a Preference 1 for all topics which is not meant for business functionality intent.

While, there are a few ways to do this, such as using a combination and tweaking of dropdownlists and other <input type>, I had some trouble searching for the same function to be served via a more intuitive Radio Input Type.

So, I decided to write a small javascript snippet to be implemented via the onclick event-handler of the <Input TYPE=radio>. The parameters to be passed into the javascript function are all the same for all the radio buttons so it will be very easy to do this programmatically in your favourite language.

The trick would be to manipuate the VALUE attribute to slot in a second Radio Group name and thereafter, have some javascript code manipuate the other radio buttons. Here is my documentation including the parameters to be passed into the javascript function:


/*
Documentation:
<INPUT TYPE=radio NAME=n1 VALUE=1_1 onclick="javascript:ClickAnotherRadioGroup(this.value,this.name)">

The Value of the Input Type=Radio must be a delimited string
The Value to the left of the pre-defined delimiter is the name of the Second Group Name
This means that while NAME signifies a Radio Group, the x of VALUE=x_actualvalue signifies the Second Radio Group
Eg.
(a) - <INPUT TYPE=radio NAME=n1 VALUE=g1_1 onclick="javascript:ClickAnotherRadioGroup(this.value,this.name)">
(b) - <INPUT TYPE=radio NAME=n1 VALUE=g2_2 onclick="javascript:ClickAnotherRadioGroup(this.value,this.name)">
belong to the same Radio Group (n1)
(c)
- <INPUT TYPE=radio NAME=n2 VALUE=g1_1 onclick="javascript:ClickAnotherRadioGroup(this.value,this.name)">
(d) - <INPUT TYPE=radio NAME=n2 VALUE=g2_2 onclick="javascript:ClickAnotherRadioGroup(this.value,this.name)">
belong to the same (but different from above) Radio Group (n2)
However, (a) and (c) belong to the same radio group as well (g1) WHILE (b) and (d) belong to another group (g2)
The Value to the right of the pre-defined delimiter is the ACTUAL VALUE of the Input Type=Radio
Note that if the ACTUAL VALUE of the Input Type=Radio uses the same delimiter, we can change our own delimiter in this function
*/


Now try this with the Javascript implementation:


function ClickAnotherRadioGroup(v,n)
{
 var f = document.forms(0);
 var n2 = v.split("_")[0]; // Retrieving the second grouped value
 for(var i=0; i<f.length; i++)
      {
 if ((f.elements[i].type == "radio") && (f.elements[i].checked) && (f.elements[i].value.split("_")[0] == n2))
  {
   var c1 = f.elements[i].value; var c2 =  f.elements[i].name;
   if ((v == c1) && (n == c2)) {} else
   {
    f.elements[i].checked = false;
   }
  }
 }
}
Try this now:

Please Vote your Favourite Topics via a Preference Gauge

  Order of Preferences
Topic 1 1 2 3
Topic 2 1 2 3
Topic 3 1 2 3

I hope this snippet will help someone as much as it has helped me.

Monday, December 26, 2005 3:59:59 AM (Malay Peninsula Standard Time, UTC+08:00)  #    Disclaimer 
  • Blog reactions

  •  Tuesday, December 13, 2005

    I am making my speaking rounds again in the usergroups and what is a better way than to start it here with our own Community Launch of VS and SQL 2005.

    Spore DotNet Usergroup, together with SQL Usergroup of Singapore, is launching our very own event on the Dec 17th 2005 to the members of both usergroups.

    We are getting the best speakers out there (and I really mean the well-seasoned experts out there) and with plenty of sponsors and support (Culminis, INETA, Product Groups), we may even try to usurp the World-Wide Launch that was held in Nov 29th 2005 in Singapore. .

    Anyways, I will be on the topic of Web Services in VS 2005 and I hope to be sharing it with the community. If you are free on that Saturday (Dec 17th 2005), do register here and drop by Microsoft Singapore.

    Do come by and Say Hello. I may play Santa and give out some freebies.

    Tuesday, December 13, 2005 5:35:10 AM (Malay Peninsula Standard Time, UTC+08:00)  #    Disclaimer 
  • Blog reactions

  • Many people I know, especially my wife, knows how hard I work to drive myself. A lot of people that I work with know that as well.

    If you want additional proof: I have been issued the standard company higher-END laptop IBM T-40 a couple of years back together with a few of my colleagues. Their screens are working fine. Look at mine now. The screen pixels are burnt out, faster than I am. Yes, I know thats what screen-savers are for - BUT I am never off the screen long enough for it to be activated. That alone will show how much (DEEP) documentation I am reading or (BAD) code I am reviewing.

    I really hope this is a great excuse to justify to the company that I work too damn hard and should be justified to get another new laptop such as this beauty OR a Pay-Raise ...

    Of course, no prizes for guessing I prefer the latter.

    ScreenPixelsBusted.JPG

    ScreenPixelsBusted1.JPG

    ScreenPixelsBusted2.JPG

    ScreenPixelsBusted3.JPG

    ScreenPixelsBusted4.JPG

    Tuesday, December 13, 2005 12:51:24 AM (Malay Peninsula Standard Time, UTC+08:00)  #    Disclaimer 
  • Blog reactions

  •  Friday, December 02, 2005

    I was approached to write about Windows Communication Foundation (WCF, previously - Indigo) a while back for SearchVB.com, a member of TechTarget.com.

    Between a few new transitional CTP drops and major Microsoft events, I managed to hack out a simple piece here targetted at entry WCF-VB developers. There is another intermediate one (that deals with security) which will appear slightly later on TechTarget.com. Stay tuned to this space for further updates.

    Do take note that this piece is currently one of the very few out there that is written against one of the latest WCF versions (The Sept-CTP WinFX drop).

    Enjoy and send those comments over.

    Thursday, December 01, 2005 10:05:28 PM (Malay Peninsula Standard Time, UTC+08:00)  #    Disclaimer 
  • Blog reactions