Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. radiobutton forecolor

radiobutton forecolor

Scheduled Pinned Locked Moved ASP.NET
javascriptdatabase
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jinnyb
    wrote on last edited by
    #1

    Dear All, i have 2 radio Buttons on my form viz. Yes & No. i assign the forecolor of these depending on the values i get from the database on page load ie.word 'Yes' in Green & 'No' in Red which is the text of my radio buttons. when the other radiobutton is selected, the color should be appropriately changed (Green for Yes & Red for No) & original forecolor of the radiobutton should be restored in black. but i do not want to utilise the checkchanged event of the radiobutton, as this will require the form to be posted back. this has to be done thro' javascript. but i do not get the forecolor attribute of the radiobutton for assigning its color. Kindly reply at the earliest. Patel Neelesh A

    G 1 Reply Last reply
    0
    • J jinnyb

      Dear All, i have 2 radio Buttons on my form viz. Yes & No. i assign the forecolor of these depending on the values i get from the database on page load ie.word 'Yes' in Green & 'No' in Red which is the text of my radio buttons. when the other radiobutton is selected, the color should be appropriately changed (Green for Yes & Red for No) & original forecolor of the radiobutton should be restored in black. but i do not want to utilise the checkchanged event of the radiobutton, as this will require the form to be posted back. this has to be done thro' javascript. but i do not get the forecolor attribute of the radiobutton for assigning its color. Kindly reply at the earliest. Patel Neelesh A

      G Offline
      G Offline
      Gavin Jeffrey
      wrote on last edited by
      #2

      Just a suggestion use it or dont use it. give the radio button a stylsheet class i.e. class="redRadio" then on your page load event add something like radionButton1.attributes.add("onclick","JavascriptFunction()") then your javascript function should do something like function JavascriptFunction() { if(radioButton1.className == "redRadio") { radioButton1.className == "greenRadio"; } else { radioButton1.className == "redRadio"; } }

      M 1 Reply Last reply
      0
      • G Gavin Jeffrey

        Just a suggestion use it or dont use it. give the radio button a stylsheet class i.e. class="redRadio" then on your page load event add something like radionButton1.attributes.add("onclick","JavascriptFunction()") then your javascript function should do something like function JavascriptFunction() { if(radioButton1.className == "redRadio") { radioButton1.className == "greenRadio"; } else { radioButton1.className == "redRadio"; } }

        M Offline
        M Offline
        Mariusz Wojcik
        wrote on last edited by
        #3

        Hi, The above idea is right, but there's small bug - as you can see watching HTML source code, ASP.NET creates RadioButton control as SPAN tag which contains INPUT and LABEL controls. Knowing that we must change the className attribute for that SPAN control, which unfortunately doesn't have an ID. The solution to this is to get INPUT’s control parent tag and change its className. The JavaScript code should look like that: // call this function to change colors function changeRadiobuttonsColorClasses() { changeRadiobuttonColorClass("rbNo", "clBgColorRed"); changeRadiobuttonColorClass("rbYes", "clBgColorGreen"); } // This function change className for control. // Params: // controlName - name of the control // className - new class name to set function changeRadiobuttonColorClass(controlName, className) { // first - find the control var el = document.getElementById(controlName); // if result is NULL, there's no control on the page if (el == null) return; // Now, find control's parent tag (should be SPAN). var elParent = el.parentNode if (elParent != null) elParent.className = className; } To assign JavaScript to control’s action you can simply type: onclick=” changeRadiobuttonsColorClasses()” in the control’s tag. -- Mariusz 'mAv' Wójcik master e-software engineer

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups