Results 1 to 2 of 2

Thread: custom checkbox script

  1. #1
    Join Date
    Oct 2008
    Location
    NJ
    Posts
    98

    custom checkbox script

    Hey! Its been awhile since I posted here, but I have a big problem. I made this script to create custom checkmarks and I dont understand why its not working. Im just starting out with Javascript and decided to give it a try.

    Here is my code:
    Code:
    // declare variables or different states
    			var off = 'images/check-off.png';
    			var on = 'images/check-on.png';
    			var normal = 'images/check-off.png'
    			
    			var radioImage = document.createElement('img');
    			var r = 0;
    			
    			function replaceRadios(){
    				
    				var radios = document.getElementById('radio1');
    				
    				// finds all radio buttons with the class of radio
    				radios.setAttribute("class","radio");
    				
    				if (radios.className == "radio") {
    					
    					// define r as 0, loop starts at 0, will continue as long as less than 10, and will be incremented 
    					for (r < 10; r++;) {
    						
    						radios[r].type == 'radio';
    						
    						// if radio is checked configure the img src to var on
    						if (radios[r].checked) {
    							
    							radioImage.src = on;
    							
    						} else {
    							
    							// otherwise configure the img src to var normal/off and give it a class of radio
    							radioImage.src = normal;
    							radioImage[className= 'radio'];
    							
    						}
    						
    						// give the image an id of radio
    						radioImage[id = 'radio'];
    						
    						radioImage.onclick= radioStates('+r');
    						
    						radios[r].parentNode.insertBefore(radioImage,radios[r]);
    						
    						// hide the radio button to show image
    						radios[r].setAttribute("class","hide");
    						
    					}
    				}
    			
    				}
    				
    				
    			function radioStates(r) {
    				
    				if(radios[r].checked='') {
    					
    					radioImage.setAttribute("class","radio off");
    					
    				} else if (radios[r].checked=true) {
    					
    					radioImage.setAttribute("class","radio on");
    				
    				} else if (radios[r].checked=false) {
    					
    					radioImage.setAttribute("class","radio off");
    				
    				} else {
    					
    					radios[r].checked=0;
    					radioImage.setAttribute("class","radio off");
    				}  
    						
        		}
    		
    		setTimeout("replaceRadios()", 0);

  2. #2
    Join Date
    Oct 2008
    Location
    NJ
    Posts
    98
    Ok, I took at the for statement, but it keeps saying radios is null

    Code:
    function replaceRadios(){
    				
    				var radios = document.getElementById('radio1');
    				
    				// sets all radio buttons with the class of radio
    				radios.setAttribute("class","radio");
    				
    				// define r as 0, loop starts at 0, will continue as long as less than 10, and will be incremented 
    				//for (r < 10; r++;) {
    						
    					radios.type == 'radio';
    						
    					// if radio is checked configure the img src to var on
    					if (radios.checked) {
    							
    						radioImage.src = on;
    							
    					} else {
    						
    						// otherwise configure the img src to var normal/off and give it a class of radio
    						radioImage.src = normal;
    						radioImage.className= 'radio';
    							
    					}
    					
    					// give the image an id of radio
    					radioImage.id = 'radio';
    				
    					radioImage.onclick= radioStates;
    						
    					radios.parentNode.insertBefore(radioImage,radios);
    						
    					// hide the radio button to show image
    					radios.setAttribute("class","hide");
    						
    				//}
    			
    			}
    				
    				
    			function radioStates() {
    				
    				if(radios.checked='') {
    					
    					radioImage.setAttribute("class","radio off");
    					
    				} else if (radios.checked=true) {
    					
    					radioImage.setAttribute("class","radio on");
    				
    				} else if (radios.checked=false) {
    					
    					radioImage.setAttribute("class","radio off");
    				
    				} else {
    					
    					radios.checked=0;
    					radioImage.setAttribute("class","radio off");
    				}  
    						
        		}
    		
    		setTimeout("replaceRadios()", 0);

Similar Threads

  1. I need help debugging a relatively simple script - I have commented it fully
    By Gebnar in forum Web Design, HTML Reference and CSS
    Replies: 0
    Last Post: 22 Jan 2008, 01:13 PM
  2. Custom Myspace Script for sale only $75.00
    By curlybird in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 0
    Last Post: 15 Jan 2007, 06:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •