Промяна на стила на checkbox
Автор: animatora
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<meta name="author" content="">
<title>Untitled 1</title>
</head>
<body>
<script>
//global variables that can be used by ALL the function son this page.
var inputs;
var imgFalse = ' false.png ';
var imgTrue = ' true.png';
//this function runs when the page is loaded, put all your other onload stuff in here too.
function init() {
replaceChecks();
}
function replaceChecks() {
//get all the input fields on the page
inputs = document.getElementsByTagName('input');
//cycle trough the input fields
for(var i=0; i < inputs.length; i++) {
//check if the input is a checkbox
if(inputs[i].getAttribute('type') == 'checkbox') {
//create a new image
var img = document.createElement('img');
//check if the checkbox is checked
if(inputs[i].checked) {
img.src = imgTrue;
} else {
img.src = imgFalse;
}
//set image ID and onclick action
img.id = 'checkImage'+i;
//set image
img.onclick = new Function('checkChange('+i+')');
//place image in front of the checkbox
inputs[i].parentNode.insertBefore(img, inputs[i]);
//hide the checkbox
inputs[i].style.display='none';
}
}
}
//change the checkbox status and the replacement image
function checkChange(i) {
if(inputs[i].checked) {
inputs[i].checked = '';
document.getElementById('checkImage'+i).src=imgFalse;
} else {
inputs[i].checked = 'checked';
document.getElementById('checkImage'+i).src=imgTrue;
}
}
window.onload = init;
</script>
<input type="checkbox" name="testBoxA" value="test1" /> Option 1<br/>
<input type="checkbox" name="testBoxB" value="test2" checked="checked" /> a checked option<br/>
<input type="checkbox" name="testBoxC" value="test3" />another checkbox<br/>
<input type="checkbox" name="testBoxD" value="test4" checked="checked" />checked again<br/>
<input type="checkbox" name="testBoxE" value="test5" /> unchecked
</body>
</html>това е кода трябват ви и картинки за избрано и не избрано поле. червените са пътя до картинките



