VNAMEDIA.NET Ebook for Share

Thursday
Sep 09th
Text size
  • Increase font size
  • Default font size
  • Decrease font size

JavaScript

CRIR: Checkbox & Radio Input Replacement

CRIR: Checkbox & Radio Input Replacement


This combination of JavaScript and CSS will hide checkbox and radio inputs that have a class = "crirHiddenJS", an id, and a proper label tag.

This will allow you to style the label however you wish using CSS, and the actual input control will be hidden. The form will still collect data as it normally would because the label itself will trigger the hidden input control. If javascript is disabled no inputs will be hidden and the form is still be fully functional.

Checkboxes

Normal (not replaced) This is the Label This is the Label with a long name This is the Label

Radio Buttons - all in the same group

Normal (not replaced) This is the Label This is the Label with a long name This is the Label

Other Samples

Green / Grey Boxes

Implementation

Using CRIR is fairly simple and you should be able to get it up and running in a couple minutes. You will need to include the crir.js javascript file and the crir.css stylesheet in the head of your page. To do so place these lines of code somewhere between the <head> and </head> tags:

<link href="/crir/crir.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" type="text/javascript" src="/crir/crir.js"></script>

You will need to change the path to the files according to your particular setup.

You then need to specify which Checkboxes and Radio Buttons you would like to replace. Add class="crirHiddenJS" to the input tag for the element you want to replace.

<input name="turtleDoves" id="checkbox1" type="checkbox" value="true" class="crirHiddenJS" />

Your input will also need a label tag. The Label tag is the standard way of... well... labelling a field!. To add a label tag you simply need to add the label tag before the input element.

<label for="checkbox1">Turtle Doves</label>
<input name="turtleDoves" id="checkbox1" type="checkbox" value="true" class="crirHiddenJS" />

Note the for attribute needs to be specified. This tells the browser which input element the label is for. Simply set the for attribute of the label equal to the value of the id attribute of the input element.

That's all there is to it. Now all you have to do is modify the CSS stylesheet file crir.css to meet your needs. The CSS gets applied to the label tag for each of the hidden input elements. The class names used are:

checkbox_checked
checkbox_unchecked
radio_checked
radio_unchecked

Take a look at the the CSS I've created to get started creating your own.

Updates

  • July 27, 2006 - Jesse Gavin sent me some improvements to the script which I have added. You no longer need to initialize the script using <body onload="crir_init()">. He's also converted the script to JSON format so it will not interfere with any other functions running on your page.
  • July 30, 2006 - Based on tip left by Adam Burmister on my blog post about CRIR I've added the ability to use the keyboard to tab to each input element and use the spacebar to check / uncheck the element. This was the one major usability flaw with CRIR, and I'm glad to have it fixed. I've also fixed a few minor bugs that were brought to my attention.
  • August 15, 2006 - Bug Fix
  • Oct 30, 2006 - Bug Fix - Special Thanks to Claudio Tassitano for pointing out the bugs.
  • Nov 16, 2006 - The script will no longer run in Safari. Safari does not support clicking on a label to toggle the form element so I've disabled this script from running on Safari as a quick fix.

Download

CRIR.zip (15kb)

Last Updated ( Monday, 11 May 2009 19:41 )

 

Custom Form Elements (CFE)

Introducing a new way of styling forms

Ever wondered how you could style form elements like checkboxes, radiobuttons and select-fields in a way you like? You tried hard using the most ass-kicking XHTML/CSS tricks, but didn't succeed without stuffing unnesscesary tags into your sleek sourcecode? Not to speak of the browsers and their "special abilities" in evaluating CSS.

Now this is for you! CFE finally found their way to SourceForge.net and allow you to style your forms individually!

Custo recommends:Watch the demo and be impressed

top

What is CFE?

A short explanation

Custom Form Elements unites all efforts in the web to enhance web-based XHTML forms in terms of style, usability and accessibility by using Javascript and/or CSS. Custom Form Elements work cross-browser, currently supporting most A-grade browsers.

The intention behind CFE is to create the one Javascript form replacement script, which may be used with mootools as well as jQuery, Prototype, YUI, Dojo, qooxdoo and so on...

It's completely unobstrusive and allows you to style your forms via CSS - so the presentation is still decoupled from the model and the logic. Yet, it still maintains or even enhances the usability of these form elements.


Advertisement



US - PC-cillin 2009

US & Canada - PaperPort Professional 11

 

Create, Preserve, Share

Acronis True Image 2009

Anti-virus software from CyberDefender

Who's Online

We have 2 guests online

BCA RSS Syndicator

Ebook4share

Email Subscriptions


Enter your email address:

Delivered by FeedBurner

Simpletags

acces action administration adobe advanced advertising agile algorithm allinone amazing american analysi ancient animation answer apache apple application april architecture aspnet attack autocad basic beautiful beginner beginning beyond bible biological blackberry blogger broadband build building busines calvin camera career certification certified circuit client codeigniter collection comet commercial communication complete compliance computer computing concept concise control cookbook create critical csharp customization cách của database definitive design designer designing developer’ development device dictionary digital directx distributed django dotnetnuke dream dreamweaver drive drupal dummie dynamic dẫn earth ebook eclipse ecommerce economic edition effect electronic embedded empire encyclopedia engine engineering english essay essential example excel exploring expres facebook feature finance firewall firstpres flash foundation framework fundamental generation giáo giới google grammar graphic great guide guitar hacking handbook hobbe house human hướng idiom illustrated including information integrated international introduction iphone january japanese javascript javaserver javatm joomla killer kiếm korea language laptop learn learning letter library linux listen lucent lập macintosh macworld magazine mambo management manual market marketing mastering mathematic matlab maxafter medical medicine meteorite method mexico microcontroller microsoft microsoft® middle millionaire missing mistake mobile modeling modern money monster multi multimedia mysql một network networking novice object office online opengl optimization oracle organic oxford paperback pattern pearl people performance personal philosophy photo photography photoshop piano planning platform platinum playboy plugin pocket pollution portal power practical practice premium prevention principle processe processing professional programmer programming project protocol python quality question reference repair resource review revised robot science search second secret secure security serie server service servlet sheet shell silico’ simple simulation slide social software solar solution something source southern spring standard steroid stock structure student studie studio study style successful synthesi system tcpip teach technique technologie technology template testing theme theory thinking third through thế thủ toefl toolkit touch trade training trick trình tutorial tình under upgrading using vector video vista visual visually vocabulary volume với website wimax window wireles wordpres world xhtml yahoo yourself