Friday 4 March 2011

jQuery: Find the label text for a selected radio button

Sometimes the seemingly easiest pieces of code can end up giving you trouble.  This morning I was working on a project where I wanted to display the text (not the value) of a selected radio button.

In the end it was very simple.  I added a label to my radio buttons and used the following line of code.

$('input[name=myname]:checked + label').text();

Read rest of entry

Tuesday 22 February 2011

SQL Concatenation with the STUFF function and XML PATH clause

Recently I had the necessity to retrieve a concatenated string of values as a column for a report.  This can be achieved quite simply by creating a UDF that returns the concatenated string and calling within the SELECT statement.

However, I do not like using UDF’s within SELECT statements due to performance issues.  So I started searching the net for a possible alternative and came across the following:

Now I have never used the SQL STUFF function or XML Path clause but the combination of the two enabled me to achieve my goal very quickly.

The STUFF function inserts a string into another string. It deletes a specified length of characters in the first string at the start position and then inserts the second string into the first string at the start position.

You can execute SQL queries to return results as XML instead of standard rowsets. These queries can be executed directly or executed from within stored procedures and user-defined functions. To retrieve the results directly, first use the FOR XML clause of the SELECT statement.

                SELECT ', ' + Username
                FROM Users
                FOR XML PATH('')
            ), 1, 1, ''
        ) As ListOfUsers
From Users

Read rest of entry

Tuesday 15 February 2011

An Introduction to Using Patterns in Web Design

A fantastic article from Ryan Singer at 37 Signals.

The use of design patterns in web design can help developers tackle the tricky balance between user experience and business objectives.

Read rest of entry

Friday 4 February 2011

SQL: OVER Clause

The OVER clause allows partitioning and ordering of the rowset.

The syntax for this function:

Ranking Window Functions

< OVER_CLAUSE > :: =

    OVER ( [ PARTITION BY value_expression, ... [ n ] ]

           <ORDER BY_Clause> )Aggregate Window Functions

< OVER_CLAUSE > :: =

    OVER ( [ PARTITION BY value_expression, ... [ n ] ] )

As specified above the OVER clause can be used in conjunction with aggregate functions, which can make your code a little shorter.

For example, consider the following bookings table:


CourseID DelegateID BookingDate BookingCost
1 1 2011-02-04 10.00
1 2 2011-02-04 10.00
2 1 2011-01-04 10.00
3 1 2011-03-04 50.00
3 2 2011-03-04 50.00

Now it is quite simple to return the total cost per delegate by using the SUM aggregate function with the OVER clause.

SELECT CourseID, DelegateID, BookingDate, BookingCost, SUM(BookingCost) OVER (PARTITION BY DelegateID) AS TotalCost FROM #Bookings

CourseID DelegateID BookingDate BookingCost TotalCost
1 1 2011-02-04 10.00 70.00
2 1 2011-01-04 10.00 70.00
3 1 2011-03-04 50.00 70.00
1 2 2011-02-04 10.00 60.00
3 2 2011-03-04 50.00 60.00

An alternative SQL sctipt without using the OVER clause would be:

SELECT CourseID, DelegateID, BookingDate, BookingCost,
    (SELECT SUM(BookingCost) FROM #Bookings BK WHERE BK.DelegateID = #Bookings.DelegateID) AS TotalCost
FROM #Bookings     

Read rest of entry

Tuesday 1 February 2011

jQuery 1.5 Released

jQuery 1.5 was released for consumption today!

Grab jQuery 1.5 here

This release includes:
  • Complete rewrite of the Ajax module.
  • New feature: Deferred Objects
  • New method: jQuery.sub()
  • Performance improvements (Adjacent Traversal)
  • Bug Fixes - Approx 83
Read rest of entry

Saturday 22 January 2011

Responsive Web Design

For me, Responsive Web Design is a relatively new term.  Basically it refers to a web design layout that alters to it's environment.  So the layout can alter depending on the screen size or resolution. This is not the same as a fluid design though, with Responsive Design the lay can actually change rather than just scale down.

I really like the idea of Responsive Web Design but it does seem a lot of effort, so I intent to start messing around with some CSS frameworks that embrace it.
Read rest of entry

Free eBook for Web Designers: 5 Tips for Better Sites

Webvantas 5 tips for better sites:

1. Draw the line between design and implementation
2. Think in terms of information architecture
3. Pick the best CMS for your needs
4. Know What jQuery Can Do for You
5. Drive traffic with SEO and social media

Free eBook for Web Designers: 5 Tips for Better Sites

A good set of guidlines which may seem obvious but are often overlooked, especially once development has begun. Many times development projects go astray because developers "cannot see the wood for the trees". I participially like tip 3 but would not limit it to the CMS, choose the right tool for job period.
Read rest of entry

Popular Posts

developer-express Copyright © 2009 Black Nero Blogspot Templatesis Designed by Ipietoon Sponsored by Online Business Journal