Solved

Get value of selected radio input button in Masterpage

Posted on 2011-02-15
4
450 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

776 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