-1

I am trying to create short yes or no radio button jQuery quiz that shows the answered div upon submit.

After the person has answered yes/no to all three questions and hit 'submit', the answer will show beneath the quiz. If they answer 'yes' to any of the questions, it will show the '#yes' option. If they answer 'no' to any of the questions, it will show the 'no' option. I just can't figure it out.

<div style="margin: 25px 0px 0px 50px;">
<form name="SurveyDemoForm" type="external" action="" method="post"  onsubmit="return OnSubmitForm();"> 

  Does your business need the ability to collect payments from your vendors?<br/><br/>
  <input type="radio" name="question-1" value="Yes" id="q1-a">Yes&nbsp;&nbsp;&nbsp;
  <input type="radio" name="question-1" value="No" id="q1-b">No<br/><br/><br/>

  Do you need to make, in any rolling three Business Days, payments more than an aggregate amount of $75,000?<br/><br/>
  <input type="radio" name="question-2" value="Yes" id="q2-a">Yes&nbsp;&nbsp;&nbsp;
  <input type="radio" name="question-2" value="No" id="q2-b">No<br/><br/><br/>

 Do you need account access for more than 10 additional users?<br/><br/>
  <input type="radio" name="question-3" value="Yes" id="q3-a">Yes&nbsp;&nbsp;&nbsp;
  <input type="radio" name="question-3" value="No" id="q3-b">No<br/><br/><br/>


  <input type="submit" id="submit" value="Submit">
</form> 
</div>

<div>
<p id="yes"><a href="#">Cash Manager Onine</a></p>
<p id="no"><a href="#">Small Business Online</a></p>
    </div>


    <script type="text/javascript"> 

     $(function() {
        var rules = ['q1-a,q2-a,q3-a']
         $('#submit').click(function() {
            $('#yes,#no').hide();
            if( $('input[name=question-1]:checked').map(function(i,v) { return v.id; }).get().join(',') == rules[0] ) {
                $("#yes").show();
             }
             else
            {   
                $("#no").show();
            }
        });
    });

    </script>
4

1 回答 1

0

有很多方法可以做到这一点,但是由于您的逻辑非常简单,因此非常简单的方法是找到:checked输入,然后遍历它们以查看是否需要应用“否”案例。

http://jsfiddle.net/m68TL/

于 2013-08-15T21:12:37.900 回答