Archive for the ‘Programming’ Category

Dynamically Colouring The Active Select List Item With JQuery/Ajax/PHP

I had a job recently where the customer wanted the items in a select list to be colour coded. My initial thought was just to use jquery and have it set the background of the selected item using the $(‘#myselect’).changed() function. The plan was that in the change event I would check the background colour of the newly selected item and then change the background colour of the select control. I wasn’t able to get the item colour though, even though the items were displaying with the various background colours – when I queried the CSS background-color attribute with jquery it would always return the same colour which was a shade of blue. I suspect it was the default colour that you see when you mouse over an item in the drop down list.

My solution was to use ajax to get the colour code for the item and then set the background colour for the list. A side effect of this was that it would set all items in the list which didn’t already have a specific background colour (some didn’t have a colour code), so I had to set each of those to #ffffff.

Here is the code and an example:

HTML Code:

In the project I was working on, we have a table that has a list of the items and the corresponding background colour. We query the table and set the background-color style attribute dynamically. For the purpose of the example I’ve simply added these manually.

<select name="selectlist" id="selectlist">
<option value="1" style="background-color:#ff0000;">The First Item 1</option>
<option value="2" style="background-color:#00ff00;">The Second Item</option>
<option value="3" style="background-color:#ffffff;">The Third Item</option>
<option value="4" style="background-color:#0000ff;">The Fourth Item</option>
</select>
Javascript Code:

We start by initialising the select list to display the correct colour for the default selected item and then we hook the .changed() event.

$(document).ready(function() {

	// Initialise the select list
	selitem=$('#selectlist :selected').val();
	$.get('/examples/ajax-functions.php?item='+selitem, function(data) {
		if(data != '')
		{
			$('#selectlist').css('background-color', data);
		}
		else
		{
			$('#selectlist').css('background-color', '#fff');
		}
	});

	// Colour code select list
	$('#selectlist').change(function(){
		selitem=$('#selectlist :selected').val();
		$.get('/examples/ajax-functions.php?item='+selitem, function(data) {
			if(data != '')
			{
				$('#selectlist').css('background-color', data);
			}
			else
			{
				$('#selectlist').css('background-color', '#fff');
			}
		});
	});
});
PHP Code:

I use a simple switch statement to get the correct background color – in the project
I queried a MySQL database and used the result from the database table.

<?
 if(isset($_GET["item"]) && is_numeric($_GET["item"]))
 {
 get_select_bg($_GET["item"]);
 }

 function get_select_bg($itemid)
 {
 switch($itemid)
 {
 case 1:
 $selbg='#ff0000';
 break;
 case 2:
 $selbg='#00ff00';
 break;
 case 3:
 $selbg='#ffffff';
 break;
 case 4:
 $selbg='#0000ff';
 break;
 default:
 break;
 }

 echo $selbg;
 }
?>

That’s about all there is to it!

WebAssist Customers Are Revolting

I guess WebAssist must have had a fairly full inbox after the recent changes to their support area. I received two followup emails that they sent to customers basically saying that due to the feedback they received, they had decided to return the peer to peer forum to its former glory and the paid support would be optional. Here is the most recent email:

It’s been quite an interesting couple of days here as we have rolled out updates to our support system. We have had overwhelmingly feedback that you like our old forum system so we wanted to let you know that we’ve put that system back in place. Our support team will be answering your questions in the forums just like they have in the past.

We will also continue to have paid-for options for customers who want guaranteed response times or to set up a phone appointment with one of our Technical Support Engineers. This should satisfy the demand we’ve been hearing for this type of support. Paid tickets and Premier appointments will ensure that you are able to resolve your issues in a timely fashion so that you can meet your deadlines.

Lastly, I wanted to thank everyone for their continued feedback. As you can imagine, not all of the feedback has been good over the past few days but I am impressed by the passion that you have shown for what we do. I hope that we have been able to show you that we do listen and that we do care about our community. I look forward to the next few months as we launch exciting new products that you will hopefully find useful and will help you be successful on the web.

I have to say that I’m pleased and a little releived that they decided to roll back those changes. WebAssist make some really classy DreamWeaver addons and they’ve always had that ‘pass me some pizza and a can of Jolt’ feel about them… programming geeks who make cool tools for other programming geeks. It would be a real shame if they destroyed that connection they have with developers.

Anyway, a big thumbs up from me and thanks for listening to your customers, WebAssist!

WebAssist – Putting Greed Before Need

I’ve used WebAssist products for several years now. They sell a number of Dreamweaver extensions such as eCart, DataAssist and Dynamic Web Charts. A recent ‘support improvement’ has changed my opinion of them from a switched on development company to just another greedy corporation that’s trying to squeeze as many doillars out of their customers as the possibly can. I won’t be purchasing any of their products again. Here’s what they said in a recent email…

In response to customer feedback, we have decided to return to private, one-on-one technical support via a new and improved ticket system. Technical support for installation and activation of our products will continue to be provided at no cost. All other technical support tickets will cost $49.99 – or you can opt to schedule a Premier phone appointment with a Technical Support expert for $99.99. We are confident that this change will allow us to continue to reduce our response time and maintain the high level of quality of support provided to you.

Any open threads currently in the forums will be resolved at no cost.  We will also leave the forums accessible for reference and there is a new feature in the support section that will allow you to search for answers across all of our support pages, tutorials, and online documentation.

So, what they are basically saying is ‘in future, rather than offering free support and sharing the solutions with the thousands of people who use this forum, we will now be charging you $50 and anyone else who needs the same solution will also have to pay $50.

Great way to raise more money and alienate your userbase, WebAssist. I’ve lost count of the number of times I’ve used the forums to find an answer to a tricky database or CSS question and now you are saying that if I want an answer to anything that isn’t covered in your documentation I have to pay?

I don’t think so!

It wouldn’t be so bad if WebAssist had simply said – ‘sorry guys, we don’t want our staff wasting their time answering questions in our support forum so we’re going to have to charge you for that, but you are welcome to continue using the forums for peer to peer support’. But no, instead what they have done is change the forums to ‘read only’ so no threads can be answered and no new posts can be submitted.

I guess there are going to be a lot more WebAssist questions asked over at Sitepoint.com in the future, where the experts don’t charge for an answer.

The mind boggles at how some ‘bright spark’ at WebAssist came up with this so called improvement. He or she is almost certainly not a developer themselves.