Link to home
Start Free TrialLog in
Avatar of wilcor14
wilcor14Flag for United States of America

asked on

Get value of selected radio input button in Masterpage

using javascript, I need to find out which radio button was selected from the group name "rPaymentMethod". I am using masterpages. Thanks.

<input id="rCreditCard" runat="server" type="radio" name="rPaymentMethod" value="CreditCard" />CreditCard
<input id="rPayPal" runat="server" type="radio" name="rPaymentMethod" value="PayPal" />PayPal
Avatar of thecrew
thecrew

Try this:

for (var i=0; i < document.formname.rPaymentMethod.length; i++)
   {
   if (document.formname.rPaymentMethod[i].checked)
      {
      var RadioValue = document.formname.rPaymentMethod[i].value;
      }
   }

Open in new window


Avatar of Anil Golamari
http://www.somacon.com/p143.php

<input id="rCreditCard" runat="server" type="radio" name="rPaymentMethod" value="CreditCard" onclick="javascript:RequestorTypeCreditCard();" />CreditCard
<input id="rPayPal" runat="server" type="radio" name="rPaymentMethod" value="PayPal" onclick="javascript:RequestorTypePayPal(); />PayPal

function RequestorTypeCreditCard()
{
document.Getelementid("RequestorType").item(0).value = True;
document.getElementById("CreditClick").value = "Y";
document.getElementById("paypalclick").value = "N";
somecode...............
}

Can you try this.
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
full sample:
<script>
function getRadioValue(rgName){
  var rbList = document.getElementsByName(rgName);
  for (i=0;i<rbList.length;i++) if (rbList[i].checked) return rbList[i].value;
}
function chkPayment(){
  var payment = getRadioValue("rPaymentMethod");
  alert(payment);
}
</script>

<input id="rCreditCard" runat="server" type="radio" name="rPaymentMethod" value="CreditCard" />CreditCard
<input id="rPayPal" runat="server" type="radio" name="rPaymentMethod" value="PayPal" />PayPal 

<button onClick="chkPayment()">Test</button>

Open in new window