.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Javascript >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Javascript function to get value of selected radio button list. If not any radio button is selected

Posted By:shiv chandra       Posted Date: June 29, 2011    Points: 40    Category: Javascript    URL: http://www.dotnetspark.com  

Javascript function to get and set value of selected radio button list. If not any radio button is selected then return empty string.
 

function getRadioValue(radioList) {
 if (document.forms['Form1'].elements[radioList]) { 
	var radGrp = document.forms['Form1'].elements[radioList];
 	var radGrpValue = '0';
 	for (var i = 0; i < radGrp.length; i++) { 
      		if (radGrp[i].checked) {
          		radGrpValue = radGrp[i].value;
                	break;
      	} 
  	return radGrpValue;
 }
 Else{
  return '';
 }
Set Value:
function SetRadioValue(radioList, newValue) {
    if (document.forms['Form1'].elements[radioList]) {
        var radGrp = document.forms['Form1'].elements[radioList];
        for (var i = 0; i < radGrp.length; i++) {
            radGrp[i].Checked = false;
            var evalue = radGrp[i].value         
            if (evalue == newValue) {
                radGrp[i].checked = true;  //radGrp[i].value = newValue;               
            }
	}
	}
}
Regards,
Shiva


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend