0

Possible Duplicate:
How can i check if a radio button is selected in javascript?

I am trying to implement client side validation on radio buttons. For example, pay status is either paid or unpaid. If they do not select any, I want it to say "Select your pay status." If either is checked, it will already display in a label through server side validation.

<script language="javascript">
$document.ready function() {
valButton = function(btn) {
for (var i=btn.length-1; i > -1; i--) {
    if (btn[i].checked) return btn[i].value;
  }
  return null;
}

if (null === valButton (document.getElementsByName (document.getElementById('rdoPaid').name)) {
  message('Select a pay status.');
}
});
</script>


Pay Status
<input ID="rdoPaid" Text="Paid" />
<br />
<input ID="rdoUnpaid" Text="Unpaid" />

Instead of input, I am really using asp:RadioButton.

This is what I was trying. Can anyone help me getting this to work properly?

Community
  • 1
  • 1
maddev
  • 17
  • 5
  • Also, if you can use jQuery, I just answered a similar question earlier today: http://stackoverflow.com/questions/12629504/issues-with-javascript-validation-of-radio-buttons-on-php-form/12631814#12631814 – Barmar Sep 28 '12 at 04:35
  • It looks like this question covers what you're after: [How can i check if a radio button is selected in javascript?](http://stackoverflow.com/questions/1423777/how-can-i-check-if-a-radio-button-is-selected-in-javascript) Check out the comments in Mark Biek's answer as they contain more info relevant to your question. – Michael Sep 28 '12 at 03:12

1 Answers1

0

Try this

if(!document.getElementById('rdoPaid').checked){
    message('Select a pay status.');
}
Sushanth --
  • 55,259
  • 9
  • 66
  • 105