radiobutton forecolor
-
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
-
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
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"; } }
-
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"; } }
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