Forum Moderators: open

Message Too Old, No Replies

Link to reflect radio button selection

         

kinkarso

12:52 am on Jun 28, 2010 (gmt 0)

10+ Year Member



Hi there,

I have a quick question about a little piece of code that I'm trying to figure out.

I am trying to get a css-styled button to stay on its 'roll-over' state once it has been selected by its corresponding radio button (connected via the label tag). So far, I have no idea what I'm doing.

Here's what I have so far:
[kinkarso.com ]

This is what it's doing:
[is.gd ]

This is what I'd like it to do:
[is.gd ]


Any experts out there that can lend a hand :)?

Thanks!
Donny

birdbrain

8:52 am on Jun 28, 2010 (gmt 0)



Hi there kinkarso,

and a warm welcome to these forums. ;)

Try it like this...


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="language" content="english">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">

<title>button</title>

<style type="text/css">

body {
font-family:verdana,arial,helvetica, sans-serif;
font-size:12px;
color:#333;
}

#container {
width:566px;
margin:auto;
}

#label {
float:left;
}

#label2 {
float:right;
}

#container a {
display:block;
width:173px;
height:132px;
padding:35px 20px 10px 85px;
background-repeat:no-repeat;
background-position:0 0;
font-family:tahoma,geneva,sans-serif;
font-size:20px;
color:#666;
text-decoration:none;
}

#container a:hover {
background-position:0 -176px;
}

#container a span {
font-size:40px;
}

#button {
background-image:url(yes.png);
}

#button2 {
background-image:url(no.png);
}

</style>

<script type="text/javascript">

function init(){
obj=document.getElementById('container');
inp=obj.getElementsByTagName('input');
anc=obj.getElementsByTagName('a');

for(c=0;c<inp.length;c++) {
inp[c].number=c;
inp[c].checked=false;

inp[c].onclick=function(){

for(c=0;c<anc.length;c++) {
anc[c].style.backgroundPosition='0 0';
}

anc[this.number].style.backgroundPosition='0 -176px';
}
}
}

if(window.addEventListener){
window.addEventListener('load',init,false);
}
else {
if(window.attachEvent){
window.attachEvent('onload',init);
}
}

</script>

</head>
<body>

<div id="container">
<label id="label" for="radio">
<input type="radio" name="radio" id="radio">
<a id="button">
<span>YES,</span><br>
I am currently a<br>
college student.</a>
</label>

<label id="label2" for="radio2">
<input type="radio" name="radio" id="radio2">
<a id="button2">
<span>NO,</span><br>
I am NOT currently<br>
a college student.</a>
</label>

</div>

</body>
</html>


birdbrain

kinkarso

8:30 am on Jun 29, 2010 (gmt 0)

10+ Year Member



Hi there,

Thanks for the warm welcome. The script works perfectly - thank you! I'm glad jQuery isn't absolutely needed for something like this.

Donny

birdbrain

8:52 am on Jun 29, 2010 (gmt 0)



No problem, you're very welcome. ;)

I'm glad JQuery isn't absolutely needed for something like this.

JQuery is like taking a sledge hammer to fix a panel pin.:)

birdbrain