2 Replies - 609 Views - Last Post: 13 November 2012 - 06:25 AM

#1 DarenR  Icon User is offline

  • D.I.C Lover

Reputation: 463
  • View blog
  • Posts: 3,166
  • Joined: 12-January 10

question on how to get the value of a radio button

Posted 13 November 2012 - 06:12 AM

I have the following code:

html side:

<input type="radio" class="trans" value="YES" id="PS_FORM/SUBJECT_PROPERTY/Sold[@Field_Type='checkbox']" name="PS_FORM/SUBJECT_PROPERTY/Sold">
                    Yes
                    <input type="radio" class="trans" value="NO" id="PS_FORM/SUBJECT_PROPERTY/Sold[@Field_Type='checkbox']" name="PS_FORM/SUBJECT_PROPERTY/Sold">No




javascript side



 function subj_sold() {

  var ctr = 0;

  var radioLength = PS_FORM/SUBJECT_PROPERTY/Sold.length;

  for (var i = 0; i < radioLength; i++) {
 
                if (PS_FORM/SUBJECT_PROPERTY/Sold[i].checked) {
 
                    alert(PS_FORM/SUBJECT_PROPERTY/Sold[i].value);
 
                    break;
 
                }
 
                ctr++;
 
            }
 
             
        }



What I want to do is get the value of either yes or no and make some other inputs either enabled or disabled. My problem is 2 fold.

1. depending on what I place in the

Quote

var =
I will either get null or always yes

2. my script breaks on the function and wont even hit an alert if it is the 1st item in the function.


thanks

Is This A Good Question/Topic? 0
  • +

Replies To: question on how to get the value of a radio button

#2 tony12095  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 14
  • View blog
  • Posts: 109
  • Joined: 23-October 12

Re: question on how to get the value of a radio button

Posted 13 November 2012 - 06:18 AM

I haven't used Javascript in a long time, and when i did, I just did simple onclick actions....but I have a question, are there boolean value variables in javascript? Or any form of an equivalent?

Try doing this: I don't know if there is a RadioButton in javascript, but you could try this and see if it leads you on the right track.

<input type="radio" class="trans" value="YES" id="PS_FORM/SUBJECT_PROPERTY/Sold[@Field_Type='<RadioButton>']" name="PS_FORM/SUBJECT_PROPERTY/Sold">Yes
 
<input type="radio" class="trans" value="NO" id="PS_FORM/SUBJECT_PROPERTY/Sold[@Field_Type='<RadioButton>']" name="PS_FORM/SUBJECT_PROPERTY/Sold">No


Was This Post Helpful? 0
  • +
  • -

#3 JMRKER  Icon User is offline

  • D.I.C Addict

Reputation: 128
  • View blog
  • Posts: 828
  • Joined: 25-October 08

Re: question on how to get the value of a radio button

Posted 13 November 2012 - 06:25 AM

This should retrieve the setting of a radiobutton group.
You can get either the value or the index of the selection.

/* Optional use in program */
function getRBtnName(GrpName) {
  var sel = document.getElementsByName(GrpName);
  var fnd = -1;
  var str = '';
  for (var i=0; i<sel.length; i++) {
    if (sel[i].checked == true) { str = sel[i].value;  fnd = i; }
  }
//  return fnd;   // return option index of selection
// comment out next line if option index used in line above  
  return str;
} 


Good Luck!
:bananaman:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1