auto select radio button depending on condtion












0















I have 10 dropdowns (Field ID: Test 1-10), with the dropdown options of Yes/No



I have a radio button (Field ID: Result) which has the option of pass/fail.



I would like a javascript where the radio button option to auto select either pass/fail.



The radio button field will auto select pass if Yes is selected 4 or more times from the dropdowns.



Thank you
Joseph










share|improve this question























  • Please take a tour of the help centre to see how to ask a good question and what types of question are on topic for the site. If you continue to ask poor quality and downvoted questions, you will get a question ban

    – Pete
    Nov 13 '18 at 15:03











  • That is a project brief, not a programming problem. Show us what you've tried so far and where you're stuck and we may be able to help.

    – DBS
    Nov 13 '18 at 15:03
















0















I have 10 dropdowns (Field ID: Test 1-10), with the dropdown options of Yes/No



I have a radio button (Field ID: Result) which has the option of pass/fail.



I would like a javascript where the radio button option to auto select either pass/fail.



The radio button field will auto select pass if Yes is selected 4 or more times from the dropdowns.



Thank you
Joseph










share|improve this question























  • Please take a tour of the help centre to see how to ask a good question and what types of question are on topic for the site. If you continue to ask poor quality and downvoted questions, you will get a question ban

    – Pete
    Nov 13 '18 at 15:03











  • That is a project brief, not a programming problem. Show us what you've tried so far and where you're stuck and we may be able to help.

    – DBS
    Nov 13 '18 at 15:03














0












0








0








I have 10 dropdowns (Field ID: Test 1-10), with the dropdown options of Yes/No



I have a radio button (Field ID: Result) which has the option of pass/fail.



I would like a javascript where the radio button option to auto select either pass/fail.



The radio button field will auto select pass if Yes is selected 4 or more times from the dropdowns.



Thank you
Joseph










share|improve this question














I have 10 dropdowns (Field ID: Test 1-10), with the dropdown options of Yes/No



I have a radio button (Field ID: Result) which has the option of pass/fail.



I would like a javascript where the radio button option to auto select either pass/fail.



The radio button field will auto select pass if Yes is selected 4 or more times from the dropdowns.



Thank you
Joseph







javascript






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 13 '18 at 14:54









Joseph OgbeweleJoseph Ogbewele

11




11













  • Please take a tour of the help centre to see how to ask a good question and what types of question are on topic for the site. If you continue to ask poor quality and downvoted questions, you will get a question ban

    – Pete
    Nov 13 '18 at 15:03











  • That is a project brief, not a programming problem. Show us what you've tried so far and where you're stuck and we may be able to help.

    – DBS
    Nov 13 '18 at 15:03



















  • Please take a tour of the help centre to see how to ask a good question and what types of question are on topic for the site. If you continue to ask poor quality and downvoted questions, you will get a question ban

    – Pete
    Nov 13 '18 at 15:03











  • That is a project brief, not a programming problem. Show us what you've tried so far and where you're stuck and we may be able to help.

    – DBS
    Nov 13 '18 at 15:03

















Please take a tour of the help centre to see how to ask a good question and what types of question are on topic for the site. If you continue to ask poor quality and downvoted questions, you will get a question ban

– Pete
Nov 13 '18 at 15:03





Please take a tour of the help centre to see how to ask a good question and what types of question are on topic for the site. If you continue to ask poor quality and downvoted questions, you will get a question ban

– Pete
Nov 13 '18 at 15:03













That is a project brief, not a programming problem. Show us what you've tried so far and where you're stuck and we may be able to help.

– DBS
Nov 13 '18 at 15:03





That is a project brief, not a programming problem. Show us what you've tried so far and where you're stuck and we may be able to help.

– DBS
Nov 13 '18 at 15:03












1 Answer
1






active

oldest

votes


















0














Not a full answer!



It must provide you an hint!



<label>yes</label><input type="radio" name="rad1" value="yes">
<label>no</label><input type="radio" name="rad1" value="no" >

<br>
<br>

<label>yes</label><input type="radio" name="rad2" value="yes" >
<label>no</label><input type="radio" name="rad2" value="no">

<br>
<br>


<label>yes</label><input type="radio" name="rad3" value="yes">
<label>no</label><input type="radio" name="rad3" value="no">



var rad = document;

var radios = document.querySelectorAll('input[type=radio]');

Array.prototype.forEach.call(radios, function(radio) {
radio.addEventListener('change', calculate);
});


function calculate(){
console.log('ss')
var count = 0;
var options = document.getElementsByName("rad1");
if (options) {
for (var i = 0; i < options.length; i++) {
if (options[i].checked){
if(options[i].value=='yes'){
count++;
}
}
}
}

var options = document.getElementsByName("rad2");
if (options) {
for (var i = 0; i < options.length; i++) {
if (options[i].checked){
if(options[i].value=='yes'){
count++;
}
}
}
}

var options = document.getElementsByName("rad3");
if (options) {
for (var i = 0; i < options.length; i++) {
if (options[i].checked){
if(options[i].value=='yes'){
count++;
}
}
}
}

if(count>2)
{
alert('count is 2 or more, paas this guy!');
}

}


JSFiddle:



https://jsfiddle.net/n0up17kb/2/






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53283721%2fauto-select-radio-button-depending-on-condtion%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Not a full answer!



    It must provide you an hint!



    <label>yes</label><input type="radio" name="rad1" value="yes">
    <label>no</label><input type="radio" name="rad1" value="no" >

    <br>
    <br>

    <label>yes</label><input type="radio" name="rad2" value="yes" >
    <label>no</label><input type="radio" name="rad2" value="no">

    <br>
    <br>


    <label>yes</label><input type="radio" name="rad3" value="yes">
    <label>no</label><input type="radio" name="rad3" value="no">



    var rad = document;

    var radios = document.querySelectorAll('input[type=radio]');

    Array.prototype.forEach.call(radios, function(radio) {
    radio.addEventListener('change', calculate);
    });


    function calculate(){
    console.log('ss')
    var count = 0;
    var options = document.getElementsByName("rad1");
    if (options) {
    for (var i = 0; i < options.length; i++) {
    if (options[i].checked){
    if(options[i].value=='yes'){
    count++;
    }
    }
    }
    }

    var options = document.getElementsByName("rad2");
    if (options) {
    for (var i = 0; i < options.length; i++) {
    if (options[i].checked){
    if(options[i].value=='yes'){
    count++;
    }
    }
    }
    }

    var options = document.getElementsByName("rad3");
    if (options) {
    for (var i = 0; i < options.length; i++) {
    if (options[i].checked){
    if(options[i].value=='yes'){
    count++;
    }
    }
    }
    }

    if(count>2)
    {
    alert('count is 2 or more, paas this guy!');
    }

    }


    JSFiddle:



    https://jsfiddle.net/n0up17kb/2/






    share|improve this answer




























      0














      Not a full answer!



      It must provide you an hint!



      <label>yes</label><input type="radio" name="rad1" value="yes">
      <label>no</label><input type="radio" name="rad1" value="no" >

      <br>
      <br>

      <label>yes</label><input type="radio" name="rad2" value="yes" >
      <label>no</label><input type="radio" name="rad2" value="no">

      <br>
      <br>


      <label>yes</label><input type="radio" name="rad3" value="yes">
      <label>no</label><input type="radio" name="rad3" value="no">



      var rad = document;

      var radios = document.querySelectorAll('input[type=radio]');

      Array.prototype.forEach.call(radios, function(radio) {
      radio.addEventListener('change', calculate);
      });


      function calculate(){
      console.log('ss')
      var count = 0;
      var options = document.getElementsByName("rad1");
      if (options) {
      for (var i = 0; i < options.length; i++) {
      if (options[i].checked){
      if(options[i].value=='yes'){
      count++;
      }
      }
      }
      }

      var options = document.getElementsByName("rad2");
      if (options) {
      for (var i = 0; i < options.length; i++) {
      if (options[i].checked){
      if(options[i].value=='yes'){
      count++;
      }
      }
      }
      }

      var options = document.getElementsByName("rad3");
      if (options) {
      for (var i = 0; i < options.length; i++) {
      if (options[i].checked){
      if(options[i].value=='yes'){
      count++;
      }
      }
      }
      }

      if(count>2)
      {
      alert('count is 2 or more, paas this guy!');
      }

      }


      JSFiddle:



      https://jsfiddle.net/n0up17kb/2/






      share|improve this answer


























        0












        0








        0







        Not a full answer!



        It must provide you an hint!



        <label>yes</label><input type="radio" name="rad1" value="yes">
        <label>no</label><input type="radio" name="rad1" value="no" >

        <br>
        <br>

        <label>yes</label><input type="radio" name="rad2" value="yes" >
        <label>no</label><input type="radio" name="rad2" value="no">

        <br>
        <br>


        <label>yes</label><input type="radio" name="rad3" value="yes">
        <label>no</label><input type="radio" name="rad3" value="no">



        var rad = document;

        var radios = document.querySelectorAll('input[type=radio]');

        Array.prototype.forEach.call(radios, function(radio) {
        radio.addEventListener('change', calculate);
        });


        function calculate(){
        console.log('ss')
        var count = 0;
        var options = document.getElementsByName("rad1");
        if (options) {
        for (var i = 0; i < options.length; i++) {
        if (options[i].checked){
        if(options[i].value=='yes'){
        count++;
        }
        }
        }
        }

        var options = document.getElementsByName("rad2");
        if (options) {
        for (var i = 0; i < options.length; i++) {
        if (options[i].checked){
        if(options[i].value=='yes'){
        count++;
        }
        }
        }
        }

        var options = document.getElementsByName("rad3");
        if (options) {
        for (var i = 0; i < options.length; i++) {
        if (options[i].checked){
        if(options[i].value=='yes'){
        count++;
        }
        }
        }
        }

        if(count>2)
        {
        alert('count is 2 or more, paas this guy!');
        }

        }


        JSFiddle:



        https://jsfiddle.net/n0up17kb/2/






        share|improve this answer













        Not a full answer!



        It must provide you an hint!



        <label>yes</label><input type="radio" name="rad1" value="yes">
        <label>no</label><input type="radio" name="rad1" value="no" >

        <br>
        <br>

        <label>yes</label><input type="radio" name="rad2" value="yes" >
        <label>no</label><input type="radio" name="rad2" value="no">

        <br>
        <br>


        <label>yes</label><input type="radio" name="rad3" value="yes">
        <label>no</label><input type="radio" name="rad3" value="no">



        var rad = document;

        var radios = document.querySelectorAll('input[type=radio]');

        Array.prototype.forEach.call(radios, function(radio) {
        radio.addEventListener('change', calculate);
        });


        function calculate(){
        console.log('ss')
        var count = 0;
        var options = document.getElementsByName("rad1");
        if (options) {
        for (var i = 0; i < options.length; i++) {
        if (options[i].checked){
        if(options[i].value=='yes'){
        count++;
        }
        }
        }
        }

        var options = document.getElementsByName("rad2");
        if (options) {
        for (var i = 0; i < options.length; i++) {
        if (options[i].checked){
        if(options[i].value=='yes'){
        count++;
        }
        }
        }
        }

        var options = document.getElementsByName("rad3");
        if (options) {
        for (var i = 0; i < options.length; i++) {
        if (options[i].checked){
        if(options[i].value=='yes'){
        count++;
        }
        }
        }
        }

        if(count>2)
        {
        alert('count is 2 or more, paas this guy!');
        }

        }


        JSFiddle:



        https://jsfiddle.net/n0up17kb/2/







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 13 '18 at 15:16









        codemirrorcodemirror

        9541026




        9541026






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53283721%2fauto-select-radio-button-depending-on-condtion%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Full-time equivalent

            Bicuculline

            さくらももこ