dimanche 25 décembre 2016

how to change the value of a text box according to checkboxes

I have made 5 checkboxes according to the one which is checked the text in the text box changes. But all the checkboxes can be checked at the same time. I want that only one checkbox to be checked at a time.

$(".check").change(function(){
        var text = "";
        $(".check:checked").each(function(){ 
            text += text != "" ? "^" : "";
            if ($(this).prop("checked"))
                text += $(this).val();
        });
        $(".text").val(text);
    });


    <script src="http://ift.tt/1oMJErh"></script>
    <input type="checkbox" class="check" value="Text1" />
    <input type="checkbox" class="check" value="Text2" />
    <input type="checkbox" class="check" value="Text3" />
    <input type="checkbox" class="check" value="Text4" />
    <input type="checkbox" class="check" value="Text5" />
    <br/>
    <input type="text" class="text" />




Aucun commentaire:

Enregistrer un commentaire