<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>ASP VB</title>
        <link>http://geekswithblogs.net/xlinesonegoal/category/9206.aspx</link>
        <description>Code related to ASP VB.</description>
        <language>en-US</language>
        <copyright>xlinesonegoal</copyright>
        <managingEditor>mail.manti@gmail.com</managingEditor>
        <generator>Subtext Version 0.0.0.0</generator>
        <item>
            <title>Selecting Items in a list using DIVs instead of Radio Buttons</title>
            <link>http://geekswithblogs.net/xlinesonegoal/archive/2008/12/01/selecting-items-in-a-list-using-divs-instead-of-radio.aspx</link>
            <description>&lt;strong&gt;&lt;font face="Arial" size="5"&gt;Selecting Items in a list using DIVs instead of Radio Buttons&lt;/font&gt;&lt;/strong&gt;
&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; Radio buttons cannot be styled using CSS. Another problem is that they simply f*** up your design if used incorrectly. They are also not very useful if you would like a user to be able to click on a large item in order to select it.&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution: &lt;/strong&gt;A solution to this problem would be to allow the user to click on whole DIVs in order to select an item. This is done using some javascript, CSS and a hidden textbox. This is how it's done using ASP VB and Javascript. Obviously this can be done using other Server Side languages as the main work will be done by Javascript. So...&lt;/p&gt;
&lt;p&gt;&lt;span style="font-weight: bold;"&gt;This is the javascript needed&lt;/span&gt;.&lt;br /&gt;
&lt;/p&gt;
&lt;span style="font-family: Courier New;"&gt;&amp;lt;script type="text/javascript"&amp;gt;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;    &lt;span style="background-color: rgb(255, 255, 0);"&gt;var selected = 0;&lt;/span&gt; //holds the selected div id... set to be the first selected item (in this case - 0)&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;    &lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;    function selectDIV(newid)&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;    {&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;        document.getElementById('div' + selected).className = 'item'; //change previously selected item CSS&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;        selected = newid; //set 'selected' as the new id&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;        document.getElementById('div' + selected).className = 'itemselected'; //change the newly selected item CSS&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;        document.getElementById('selecteddivid').value = selected; //set value of hidden textbox to selected div id&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;    }&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;p&gt;The highlighted part in this code is the most important thing. The 'selected' variable holds the ID Number of the selected DIV. It is important to set it by default as the item selected when the page loads.&lt;/p&gt;
&lt;span style="font-weight: bold;"&gt;This is the HTML/ASPVB code needed&lt;/span&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-family: Courier New;"&gt;    &amp;lt;% for i = 0 to 5 &lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;        if i = 0 then&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;            myclass = "itemselected"&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;        else&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;            myclass = "item"&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;        end if&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;        &lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;        &lt;span style="background-color: rgb(255, 255, 0);"&gt;divid = "div" &amp;amp; i&lt;/span&gt;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;    %&amp;gt;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;        &amp;lt;div class="&amp;lt;%= myclass %&amp;gt;" &lt;span style="background-color: rgb(255, 255, 0);"&gt;id="&amp;lt;%= divid %&amp;gt;" onclick="selectDIV(&amp;lt;%= i %&amp;gt;)&lt;/span&gt;"&amp;gt;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;            To select DIV #&amp;lt;%= i %&amp;gt; click here.&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;        &amp;lt;/div&amp;gt;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;    &amp;lt;% next %&amp;gt;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;    &lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;    &amp;lt;form action="default.asp" method="post"&amp;gt;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;        &lt;span style="background-color: rgb(255, 255, 0);"&gt;&amp;lt;input type="hidden" id="selecteddivid" name="selecteddivid" value="0" /&amp;gt; &lt;/span&gt;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;        &amp;lt;input type="submit" value="SAVE" /&amp;gt;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;    &amp;lt;/form&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
In this case, I used a loop from 0 to 5 to generate 6 divs. The ID of each DIV is 'div&lt;span style="color: rgb(128, 128, 128);"&gt;x&lt;/span&gt;' where x is a number from the loop. The onclick event calls the selectDIV function which we did above. As you can see a hidden textbox 'selecteddivid' is created here which will hold the selected div's id. This can later be read using &lt;span style="font-family: Courier New;"&gt;request.form("selecteddivid") &lt;span style="font-family: Arial;"&gt;after the form posts.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;p&gt;&lt;strong&gt;Conclusion: &lt;/strong&gt;Javascripts like this are easy to create and will help you create better-looking webpages by allowing the user to interact better with your website.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;span style="font-weight: bold; text-decoration: underline;"&gt;Code example will be coming soon.&lt;/span&gt;&lt;br /&gt;
&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=127478"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=127478" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/xlinesonegoal/aggbug/127478.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>xlinesonegoal</dc:creator>
            <guid>http://geekswithblogs.net/xlinesonegoal/archive/2008/12/01/selecting-items-in-a-list-using-divs-instead-of-radio.aspx</guid>
            <pubDate>Mon, 01 Dec 2008 15:20:14 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/xlinesonegoal/comments/127478.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/xlinesonegoal/archive/2008/12/01/selecting-items-in-a-list-using-divs-instead-of-radio.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/xlinesonegoal/comments/commentRss/127478.aspx</wfw:commentRss>
        </item>
    </channel>
</rss>