Adding validations to see if radio button is not selected

前端 未结 8 1059
误落风尘
误落风尘 2021-01-07 06:30

I have the following code:

 
  • 1. question 1
  • Strongly
  • 相关标签:
    8条回答
    • 2021-01-07 06:56

      You should use logical operator && for your condition

      if ( (thisfrm.question3[0].checked == false) && 
           (thisfrm.question3[1].checked == false) && 
           (thisfrm.question3[2].checked == false) && 
           (thisfrm.question3[3].checked == false) && 
           (thisfrm.question3[4].checked == false) )
      
      0 讨论(0)
    • 2021-01-07 06:57

      Below code is more simple and clean for even biggners

      if (!$("input[name='html_elements']:checked").val()) {
         alert('Nothing is checked!');
      }
      else {
        alert('One of the radio buttons is checked!');
      }
      

      check out this below fiddle demo

      Visit http://jsfiddle.net/creators_guru/DBd79/

      0 讨论(0)
    提交回复
    热议问题