Changing radio buttons to images - a little help please.
Hello, someone has kindly written up a jquery script that will change my radio buttons to images, he even showed me a demo of it working via http://jsfiddle.net/elclanrs/BQp2F/.
The problem is, I cant get it to work, and if you open that demo, place my source code in the HTML window and press RUN it doesn't work either.
NOTE: I have saved and uploaded these as jscript_customradio.js and style_customradio.css and as expected it does not work. Here is my screenshot to show it's all loaded with no errors: http://i50.tinypic.com/o0qdde.jpg
init:function(o){
var ary=[],obj,img,imgs=[],oop={ary:[]},z0=0;
for (;z0<o.IDs.length;z0++){
imgs[z0%2]=new Image();
imgs[z0%2].src=o.ImageSRCs[z0%2];
obj=document.getElementById(o.IDs[z0]);
if (obj){
img=document.createElement('IMG')
img.src=imgs[0].src;
this.addevt(img,'mouseup','check',oop,img);
oop.ary.push([obj,img,imgs]);
obj.parentNode.insertBefore(img,obj);
obj.style.position='absolute';
obj.style.visibility='hidden';
}
}
this.check(oop);
},
check:function(o,img){
for (var z0=0;z0<o.ary.length;z0++){
if (img&&o.ary[z0][1]==img){
o.ary[z0][0].checked=true;
}
}
for (var z0=0;z0<o.ary.length;z0++){
o.ary[z0][1].src=o.ary[z0][2][o.ary[z0][0].checked?1:0].src;
}
},
addevt:function(o,t,f,p,p1){
var oop=this;
if (o.addEventListener){
o.addEventListener(t,function(e){ return oop[f](p,p1);}, false);
}
else if (o.attachEvent){
o.attachEvent('on'+t,function(e){ return oop[f](p,p1); });
}
}
one, there is a semi colon before your function declaration in your jscript_customradio.js file, which might mean nothing, but probably isn't helping: ;(function(){
the bigger one is that you should be waiting for your elements to be rendered before trying to alter them - and being that you have placed this script in the head, that hasn't happened yet.
I would try putting the function call in a document ready wrapper:
one, there is a semi colon before your function declaration in your jscript_customradio.js file, which might mean nothing, but probably isn't helping: ;(function(){
the bigger one is that you should be waiting for your elements to be rendered before trying to alter them - and being that you have placed this script in the head, that hasn't happened yet.
I would try putting the function call in a document ready wrapper:
Thank you, I have corrected both and now the radio buttons have become images, however there are 2 issues...
The radio buttons can only be selected if you click just to the right of it (the label).
They can all be selected instead of just the 1 per group as expected.
It's probably too difficult for me to attempt, but how hard would it be to have each radio button use a different image, would it require a lot of editing?