Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Get value of selected radio input button in Masterpage

Posted on 2011-02-15
4
Medium Priority
?
466 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 2000 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 61

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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

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 task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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…
Suggested Courses

971 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