5,276,801 members and growing! (16,014 online)
Email Password   helpLost your password?
Web Development » Client side scripting » General     Intermediate

Inputer Replacer

By Anthony Main

Javascript implementation to make standard form <input> radios or checkboxes visually attractive by exchanging with images.
Javascript, HTML, Windows, Visual Studio, Dev

Posted: 1 Nov 2005
Updated: 1 Nov 2005
Views: 13,810
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
6 votes for this Article.
Popularity: 3.11 Rating: 4.00 out of 5
0 votes, 0.0%
1
0 votes, 0.0%
2
1 vote, 16.7%
3
1 vote, 16.7%
4
4 votes, 66.7%
5

Introduction

The age old problem of styling HTML inputs has plagued developers for years, as the current CSS rules (<2.0) provide limited scope for styling. This method offers a solution to this problem by replacing all page inputs (of type radio or checkbox) with appropriate image representations.

Background

The original code was written by BrainError. All credits are to him for his methodology. I have simply extended the functionality of his code by adding support for radio buttons and disabled inputs. Please visit his site for the original implementation.

Using the code

The code is completely self contained. You simply need to add the JS file to any of your pages where you want the replacement to occur and it will do the biz for you. Simply add the following to the HEAD section of your HTML pages or copy and paste all the code into your JS source:

<script language="JavaScript" src="wdx_inputreplacer.js">
</script>

Open the JS file and update the following lines with appropriate locations to your images for replacement:

var imgCheckboxFalse = 'images/checkbox_unchecked.gif';
var imgCheckboxTrue = 'images/checkbox_checked.gif';
var imgCheckboxFalseDisabled = 
              'images/checkbox_unchecked_disabled.gif';
var imgCheckboxTrueDisabled = 
               'images/checkbox_checked_disabled.gif';
var imgRadioFalse = 'images/radio_unchecked.gif';
var imgRadioTrue = 'images/radio_checked.gif';
var imgRadioFalseDisabled = 
               'images/radio_unchecked_disabled.gif';
var imgRadioTrueDisabled = 
               'images/radio_checked_disabled.gif';

You could remove the line:

window.onload = init;

from the bottom of the JS source file and call the init() function from your page's BODY or manually if you like.

The code is highly cross-browser compatible as the method is very basic. It will also continue to provide the functionality (without the visual improvements) if JavaScript is disabled.

Notes before use

All inputs must be given unique IDs (which is fine if you are a .NETter) otherwise the script will not be able to identify which input has been checked/unchecked.

Future changes

The current implementation is not accessible as the images swapped in do not strictly exist in the DOM therefore cannot be tabbed to. If I find the need I will update this article with a method to do so. However, it would require pre-adding the visual images into the page source and therefore would not be as "plug and play" as this version, however it may provide a method for the replacement of specific inputs rather than all.

References

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Anthony Main


Anthony Main started developing and designing web sites as far back as 1996 using traditional HTML. His skills have now grown and he is a professional .net developer, with skills in c#, vb.net, css, xhtml.

Running his own company Web DynamiX (in his spare time) he develops web solutions for small to medium size businesses and provides hosting and consultancy solutions.

His main occupation is of web developer where is works for Branded 3/a> developing .Net projects for medium to enterprise businesses.

You can read his personal blog at:
http://blog.anthonymain.com.
Occupation: Web Developer
Location: United Kingdom United Kingdom

Other popular Client side scripting articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 6 of 6 (Total in Forum: 6) (Refresh)FirstPrevNext
Subject  Author Date 
Questionsame questionmemberMarkus19743:23 21 Nov '07  
QuestiononClick actionsmemberMarkus19746:05 21 Oct '07  
GeneralLabel SupportmemberBWD20:34 14 Nov '05  
GeneralRe: Label SupportmemberAnthony Main23:50 14 Nov '05  
GeneralLabel supportmemberBWD13:16 14 Nov '05  
QuestionGreat, nothing morememberdaniero8:34 8 Nov '05  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 1 Nov 2005
Editor: Rinish Biju
Copyright 2005 by Anthony Main
Everything else Copyright © CodeProject, 1999-2008
Web17 | Advertise on the Code Project