error validate radio button

Results 1 to 2 of 2

Thread: error validate radio button

  1. #1
    Join Date
    Dec 1969

    Default error validate radio button

    hi, <BR>my code cannot validate for unchoose/choose when there&#039;s only 1 radiobutton. It would display &#039;Please choose 1 radio button&#039; even i did choose the radiobutton . But this code can validate if i have more than 1 radiobutton. <BR><BR>So what&#039;s wrong wif it? Anyone can help mi? <BR>---------------------------------------------------------- <BR><BR>function checkChoose(){ <BR><BR>var c = ""; <BR><BR> for (var b = 0; b &#060; document.frmdeleteStaffUsers.staff_no.length; b++){ <BR><BR> if (document.frmdeleteStaffUsers.staff_no[b].checked == true ){ <BR>c = c + document.frmdeleteStaffUsers.staff_no[b].value <BR>}; <BR><BR>}; <BR><BR>if (c == "" ){ <BR>window.alert ("Please choose 1 radiobutton"); <BR>window.event.returnValue = false; <BR>}; <BR>}; <BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: error validate radio button

    Usually, radio buttons are used in a different way then with checkboxs.<BR><BR>When using checkboxs you basically allow the user to chose whatever if/she wants. If they want they can leave all the checkboxs unchecked.<BR><BR>Radio buttons usually has one default value. When your page loads, one of your radio button should be selected by default. The idea behind a radio button is that you can&#039;t uncheck it you have to select one and that&#039;s why we usually select one by default.<BR><BR>Like I said, this is usually why you should decide between radio buttons and/or checkboxs.<BR><BR>Checkboxs allows the user to unselect their choice or even leave them all unchecked.<BR>Radio buttons(usually a group) allows the user to chose a different option BUT you&#039;ll always end up with at least one radio button checked.<BR><BR>The reason I&#039;m saying that is that it&#039;ll allow you NOT to create a validation function for your radio buttons. Just make one of your radio buttons the default one and your validation nedeed.<BR><BR>Sincerely<BR>Vlince

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts