Shaun Mccran

My digital playground

23
D
E
C
2010

Using JQuery to disable all form fields

Whilst writing a new timesheet application I added a function to 'lock' an entire dataset, IE stop a user from editing the form on the page.

I'd spent a lot of time layout the timesheet page, designing the form, and help text etc. I didn't really want to destroy the visuals if a record was locked, I wanted it just the same, but 'non-active'.

This is where JQuery is simply awesome. Understanding 'selectors' and the power they can give you, with only very simple construction is key.

In this example imagine a page that has a div within it, the div has a id of 'divLabel'. Within that div there is a form. The code below will disable all the input elements within that div. Every single one of them. In one line of code. How cool is that.

view plain print about
1<s/cript type="text/javascript">
2    $(document).ready(function(){
3        $('#divLabel :input').attr('disabled', true);
4    });
5    // end
6</script>

What its actually doing is adding the disabled attribute to each input, then setting the value to 'true'.

Get familiar with how JQuery selectors work, the docs are here: http://api.jquery.com/category/selectors/

22
D
E
C
2010

Filtering a SELECT field using AJAX and JQuery

I've got a select form field, and I want it to change based on a search string that someone enters. Luckily for me the select field is dynamically driven from a database, so the most obvious way for me to do this is to make an AJAX post request using the string entered to amend the SQL query building the field.

This article shows you how to do this, there is a demo of the select field using AJAX here: http://www.mccran.co.uk/examples/jquery_textfilter_selectfield/

[ More ]

19
D
E
C
2010

The mathematics of solving the UK snow problem

I've had enough of the UK news whining about the weather conditions. I was raised in Scandinavia, where they have a more resolute disposition towards the snow. It is something that happens every year, and you learn to get on with it.

So I got to thinking, what do I do when it snows? I get out there and I clear it off. I grab the shove/broom and I clear it out of the way. What would happen if the able bodied population of the country did the same, instead of sitting around complaining? Manpower is free, and its readily available.

This article examines the theoretical maths involved in that idea.

[ More ]

16
D
E
C
2010

Showing and hiding Divs using JQuery and a select field

Ever want to show and hide div elements using form controls? JQuery makes this sort of functionality super easy.

In this blog entry I'll show you how to create a simple JQuery function that shows and hides elements based on a form select field.

You can see an example of the finished script here: Demo JQuery show / hide using a select field

[ More ]

_UNKNOWNTRANSLATION_ /