Solved

Get value of selected radio input button in Masterpage

Posted on 2011-02-15
4
448 Views
Last Modified: 2012-06-22
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
0
Comment
Question by:wilcor14
4 Comments
 
LVL 3

Expert Comment

by:thecrew
ID: 34899809
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


0
 
LVL 18

Expert Comment

by:Anil Golamari
ID: 34899846
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.
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 34899977
Check this :
var rb1 = document.getElementById("<%= rCreditCard.ClientID %>");
var rb2 = document.getElementById("<%= rPayPal.ClientID %>");

if( rb1.checked ) {
   method = rb1.value;
}
else if( rb2.checked ) {
   method = rb2.value;
}
else {
   method = "None";
}

Open in new window

0
 
LVL 51

Expert Comment

by:HainKurt
ID: 34899987
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

0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now