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 11 of 11
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    England =)
    Posts
    523
    Thanks
    26
    Thanked 0 Times in 0 Posts

    control radio background colour via script?

    Hi all,

    i need a script that will override all the background colours of MANY radio buttons i have on a form (its HUGE!!!)

    i have:

    Code:
    function doRadio() {
    
    var rbg = document.body.all.tags("input");
      for (var i = 0; i < rbg.length; i++)
        rbg[i].bgColor= '#E6F4F4';
    }
    i think the principle is sound but obvously radio is a subgroup of INPUT... any ideas?
    "They hired me for my motivational skills. Everyone at work says they have to work much harder when I`m around" Homer J Simpson

  • #2
    Senior Coder
    Join Date
    Jul 2004
    Location
    New Zealand
    Posts
    1,315
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Try
    Code:
        rbg[i].backgroundColor= '#E6F4F4';
    though I'm not sure you can even colour radio buttons. And check
    Code:
    rbg.type == 'radio'
    Forget style. Code to semantics. Seperate style from structure, and structure from behaviour.
    I code to specs, and test only in Firefox (unless stated otherwise).

  • #3
    Regular Coder
    Join Date
    Nov 2003
    Location
    Vancouver Island Canada
    Posts
    139
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
     <input type="radio" style="background :blue">

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    Quote Originally Posted by glenmac
    Code:
     <input type="radio" style="background :blue">
    That will make the square surrounding the circle blue in IE but nothing in FF. If what the poster actually wants is to color the inside of the circle, it's not possible.

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    Edit: sorry, doubled reply (blame it to our intermittent internet connection )

  • #6
    Regular Coder
    Join Date
    Jun 2002
    Location
    England =)
    Posts
    523
    Thanks
    26
    Thanked 0 Times in 0 Posts

    Unhappy

    thanks for the input (no pun intended - its too early!)

    Code:
    function doRadio() {
    
    var rbg = document.body.all.tags('input');
    	for (var i = 0; i < rbg.length; i++) {
        		rbg[i].style.backgroundColor='#E6F4F4';
        		rbg[i].style.border='0';
    	}
    }
    that does it for all radio, check, text etc. the problem is that i need to just do it for radio buttons. i would normally do class="radio" etc but im using lotus notes for my database power and its WYSIWYG form elements ( i hand code the html tho ) means it is a pain in the (_,_) to change the 200+ radio buttons on this page! and i have another similar form to do.

    surely this is possible isnt it?
    "They hired me for my motivational skills. Everyone at work says they have to work much harder when I`m around" Homer J Simpson

  • #7
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    function doRadio() {
    var rbg = document.getElementsByTagName('input');
    for (var i = 0; i < rbg.length; i++) {
    if(rbg[i].getAttribute('type')=='radio'){
    rbg[i].style.backgroundColor='#E6F4F4';
    rbg[i].style.border='0px';
    }
    }
    }

    correct an error. Note: this code wou'nt work for Mozilla. For moz radio's background has no meaning
    Last edited by Kor; 04-21-2005 at 09:57 AM.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #8
    Regular Coder
    Join Date
    Jun 2002
    Location
    England =)
    Posts
    523
    Thanks
    26
    Thanked 0 Times in 0 Posts
    crap!

    i just did this:

    Code:
    function doRadio() {
    
    var rbg = document.getElementsByTagName('input');
    	for (var i = 0; i < rbg.length; i++) {
    		if(rbg[i].type == 'radio') {
        			rbg[i].style.backgroundColor='#FFFFFF';
        			rbg[i].style.border='0';
    		}
    	}
    }
    thanks for the prompt response btw!

    any ideas which would be more browser compatible?
    Last edited by babelfish; 04-21-2005 at 09:56 AM.
    "They hired me for my motivational skills. Everyone at work says they have to work much harder when I`m around" Homer J Simpson

  • #9
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    function doRadio() {
    var rbg = document.getElementsByTagName('input');
    for (var i = 0; i < rbg.length; i++) {
    if(rbg[i].getAttribute('type')=='radio'){
    rbg[i].style.backgroundColor='#E6F4F4';
    rbg[i].style.border='0px';
    }
    }
    }

    correct an error. Note: this code woun't work for Mozilla. For moz radio's background has no meaning
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #10
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    Quote Originally Posted by babelfish
    any ideas which would be more browser compatible?
    I don't think there's a way for Moz-based browsers to color the radio button. As you will notice when you tab to set focus to radio button, the size of the control is only as big as the circle so there's nothing to color to. While in IE the size is bigger. Both browsers don't allow color inside the circle itself.

  • #11
    Regular Coder
    Join Date
    Jun 2002
    Location
    England =)
    Posts
    523
    Thanks
    26
    Thanked 0 Times in 0 Posts
    that doesnt matter... i really want them to be white BG anyway. i just control the border and BG of form inputs to make them fit the colour scheme... thanks for your help all!
    "They hired me for my motivational skills. Everyone at work says they have to work much harder when I`m around" Homer J Simpson


  •  

    Posting Permissions

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