By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,848 Members | 3,223 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,848 IT Pros & Developers. It's quick & easy.

radiobutton list

P: 9
How can we check in java script whether the user
selected radio button list items or not
Sep 30 '08 #1
Share this Question
Share on Google+
3 Replies


Markus
Expert 5K+
P: 6,050

P: 9
Expand|Select|Wrap|Line Numbers
  1. var  radio =document.getElementById('newradiobutton')
  2. var radiotrue=0;
  3.  
  4. for (var i=0; i<radio.length; i++)
  5.              {
  6.              alert(i);
  7.              if (radio[i].checked)
  8.              {
  9.              radiotrue=1;
  10.              }
  11.              }
  12.              alert(radiotrue);
  13.              if (radiotrue==0)
  14.              {
  15.              showgroupfields();
  16.              return false;
  17.              }

even if the user selects radio button the radiotrue value id 0.
Sep 30 '08 #3

acoder
Expert Mod 15k+
P: 16,027
document.getElementById() gets only one element. To get a list of radio buttons, use document.getElementsByName("radiobuttons").
Sep 30 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.