2021年1月17日星期日

Random select Radio button from multiple radio group

I had 6 set of radio group and each group have 4 radio buttons.

<script>  function callRandom() {          for (var i = 0; i < 4; i++) {            var contestants = ["groupA", "groupB", "groupC", "groupD", "groupE", "groupF"];          var contestantsNumber = contestants.length;            var randomNumber = Math.floor(Math.random() * contestantsNumber);          var randomWinner = contestants[randomNumber];          // var randomWinner1 = contestants[randomNumber];          // var x = document.getElementById("winner");          console.log(randomWinner);            var array = document.getElementsByName(randomWinner);          // console.log(array)            var randomNumber = Math.floor(Math.random() * 4);            array[randomNumber].checked = true;      }    }  

Currently this code work perfectlyand it will select random 4 groups from array and random pick a radio button. But i wan only select once from the array. For example if groupA is selected, i dont wan to be picked agn.
**ps: I want display each selection. i wanna get [0] values until [3] values and display it in html. how to get the text"groupA" enter image description here

https://stackoverflow.com/questions/65768862/random-select-radio-button-from-multiple-radio-group January 18, 2021 at 12:31PM

没有评论:

发表评论