How To Get The Selected Value In A RadioButtonList Via JavaScript

<script type="text/javascript">
    function SelectedRBL() {
        var list = document.getElementById('<%= rblPollAnswers.ClientID %>'); //Client ID of the radiolist
        var inputs = list.getElementsByTagName("input");
        var selected;
        for (var i = 0; i < inputs.length; i++) {
            if (inputs[i].checked) {
                selected = inputs[i];
                break;
            }
        }
        if (selected) {
            alert(selected.value);
        }

    } 
</script>

<asp:RadioButtonList ID="rblPollAnswers" runat="server" />
<asp:Button ID="btnVote" runat="server" Text="Vote" OnClientClick="SelectedRBL();return false;" />
Advertisements

3 thoughts on “How To Get The Selected Value In A RadioButtonList Via JavaScript

    • function getdata() {
      var p = document.getElementById(“”)
      var a = document.getElementById(“”)
      var q = document.getElementById(“”)
      var r = document.getElementById(“”)
      var total;
      var radval =0;
      var cptfeearr = new Array();
      cptfeearr[“0”] = 6100;
      cptfeearr[“1”] = 6100;
      cptfeearr[“2”] = 30450;
      cptfeearr[“3”] = 6100;
      cptfeearr[“4”] = 30450;

      var s = document.getElementById(“”)

      for (var i = 0; i < s.Length; i++) {
      if (s[i].checked==true) {

      radval = s[i].value;

      break;
      }

      }

      total = parseInt(cptfeearr[radval]);
      if (q.checked) {
      total = total + 200;

      }
      if (r.checked) {
      total = total + 400;
      }

      p.innerHTML = "INR" + parseInt(total) + "/-";

      document.getElementById("”).value = total;

      }

      i write the above code but it is not working properly it give only first index out put means 6100+checkbox value but my target is radiobuttonlistitem value with checkvalue shoing in innerhtemof label

  1. function getdata() {
    var p = document.getElementById(“”)
    var a = document.getElementById(“”)
    var q = document.getElementById(“”)
    var r = document.getElementById(“”)
    var total;
    var radval = 0;
    var cptfeearr = new Array();
    cptfeearr[0] = 6100;
    cptfeearr[1] = 6100;
    cptfeearr[2] = 30450;
    cptfeearr[3] = 6100;
    cptfeearr[4] = 30450;

    var s = document.getElementById(“”)
    // var inputs = s.getElementsByTagName(“input”);
    for (var i = 0; i < s.Length; i++) {
    if (s[i].checked)
    {
    radval = s[i].value;
    break;
    }
    }
    total = parseInt(cptfeearr[radval]);
    if (q.checked) {
    total = total + 200;
    }
    if (r.checked) {
    total = total + 400;
    }
    p.innerHTML = "INR" + parseInt(total) + "/-";
    document.getElementById("”).value = total;
    }

    I am getting the first value in the radiobuttonlist but how shall i get the second, third or rest by selecting radio buttonlist

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s