Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jul 2008
    Posts
    64
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Question radio button help

    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

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

  • #2
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    Give your radio buttons a name:
    Code:
    <input type='radio' onclick='document.bgColor="black"' name="color">
    <input type='radio' onclick='document.bgColor="blue"' name="color"/>
    Sidenote, bgcolor is a deprecated attribute. You're better off using CSS on it.

    Hope that helps.
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • #3
    New Coder
    Join Date
    Jul 2008
    Posts
    64
    Thanks
    12
    Thanked 0 Times in 0 Posts
    sir, am a noob..i don't know CSS.. that's why am asking on how will i fix the radio button

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,801
    Thanks
    160
    Thanked 2,216 Times in 2,203 Posts
    Blog Entries
    1
    See reset radio buttons to unchecked
    BTW, use the standard style object to change the background color, see Example-5 at http://wwww.w3schools.com/htmldom/dom_using.asp
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #5
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    Code:
    <input type='radio' onclick='document.body.style.backgroundColor="#000"' name="color">
    <input type='radio' onclick='document.body.style.backgroundColor="#00f"' name="color"/>
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph


  •  

    Posting Permissions

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