Banner

Sponsor

Login


Welcome Back!
Guest
Guest

Register

Lost your password?

52 users online



javascript = whats wrong wit this code?

javascript = whats wrong wit this code?

Currently viewing this thread: 1 (0 members and 1 guests)


asmega

asmega

Status: Offline!

javascript = whats wrong wit this code?

cant get this code to work

<script type="text/javascript">
//<![CDATA[
onload = function()
{
for(i=0; i<document.getElementsByTagName('input'); i++)
{
if(document.getElementsByTagName('input')[i].type == 'checkbox')
{
var c = document.getElementsByTagName('input')[i];
c.parentNode.parentNode.style.backgroundColor = (c.checked) ? '#f00' : '#090';
}
}
}
//]]>
</script>

___________________

No one will ever know the meaning of life.

CyberKill3r

CyberKill3r

Status: Offline!

you would have to put that between the body tag

___________________

Grand Premier of CyberKill3r Episode I website on some time in the future. With a lot of tutorials and scripts free to download, and much more...
..::CyberKill3r.

Sykil

Sykil

Neversidian
Status: Offline!

Are you trying to do this? If so just compare the two codes.

___________________

http://imagegen.last.fm/artist/artists/Sykil.gif
Free-Speed Nation

asmega

asmega

Status: Offline!

putting into the body tag makes no difference whatsoever

and yes - but no one would reply to that

and im trying to get to work for more than one cell and checkbox so a for loop is required but it wont work?

i do not know how javascript works

___________________

No one will ever know the meaning of life.

JimT

JimT

Status: Offline!

This might help:

Code:

function SetCellBGs()
{
var FormInputs = document.getElementsByTagName('input');

for (var i = 0; i < FormInputs.length; i++)
{
if (FormInputs[i].type == "checkbox")
{
if (FormInputs[i].checked == true)
{
FormInputs[i].parentNode.style.background = "blue";
}
else
{
FormInputs[i].parentNode.style.background = "red";
}
}
}
}

Quick Jump:

Main Navigation


Site & Graphic Design by Aeon Tan
Developed by Jeremie Pelletier & Scott Roach


NeverAPI generated this page in 0.0077 seconds.