View Full Version : radio button help

07-30-2008, 07:32 AM
hello am new to this forum and i just started out reading javascript lessons

i made a script with an onclick even to the radio buttons, and the clicked button changes the background. my question is. how will you make it appear like only one button is being marked at a time..because when i click the radio buttons in my script..both are being marked and i can't remove the mark unless i restart the file on the browser.

here's my code

<input type='radio' onclick='document.bgColor="black"'>
<input type='radio' onclick='document.bgColor="blue"' />

07-30-2008, 07:37 AM
Give your radio buttons a name:

<input type='radio' onclick='document.bgColor="black"' name="color">
<input type='radio' onclick='document.bgColor="blue"' name="color"/>

Sidenote, bgcolor is a deprecated attribute (http://www.codehelp.co.uk/html/deprecated.html). You're better off using CSS on it.

Hope that helps.

07-30-2008, 07:41 AM
sir, am a noob..i don't know CSS.. that's why am asking on how will i fix the radio button

07-30-2008, 07:41 AM
See http://www.codingforums.com/showthread.php?t=20609
BTW, use the standard style object to change the background color, see Example-5 at http://wwww.w3schools.com/htmldom/dom_using.asp

07-30-2008, 07:52 AM
<input type='radio' onclick='document.body.style.backgroundColor="#000"' name="color">
<input type='radio' onclick='document.body.style.backgroundColor="#00f"' name="color"/>