0
    <form id="v-1">
        <input type="radio" name="ot-1" value="o-1" /> answer1
        <input type="radio" name="ot-1" value="o-2" /> answer2
        <input type="radio" name="ot-1" value="o-3" /> answer3
        <input type="radio" name="ot-1" value="o-4" /> answer4
    </form>

How to make: if checked Answer 1, then in var test adds 1 point, if one of other Answers cheked, then adds 0 points?

2 Answers 2

5
<form id="v-1">
    <input type="radio" name="ot-1" value="o-1" /> answer1
    <input type="radio" name="ot-1" value="o-2" /> answer2
    <input type="radio" name="ot-1" value="o-3" /> answer3
    <input type="radio" name="ot-1" value="o-4" /> answer4
</form>

JS:

<script>

    test = 0;
    $('input[name=ot-1]').click(function(){
        if($(this).val()=="o-1"){
            test=test+1;
        }
    });
</script>
Sign up to request clarification or add additional context in comments.

Comments

1

In jquery you can use the following to get the value of a checked radio button

var value = $("input[@name=ot-1]:checked").val();

U can use this in a button event:

$('#submit_button').click(function() {
    var value = $("input[@name=ot-1]:checked").val();
    var test=0;
    if (value == "o-1") {
        test = 1;
    }
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.