Solved

Get value of selected radio input button in Masterpage

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
document.write() deleting all existing HTML 5 49
how can i turn the array into an object 4 39
Json Schema 8 32
Search Item in Table 2 19
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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…

808 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