Menu Close

How to append the Checkbox Value to another input Using jQuery?


Here we are using the jQuery click() function to assign the value to the textbox with the action of checkbox. Whenever the checkbox is clicked to check or uncheck, it assigns the respective return value into the textbox.

<!DOCTYPE html>
    <script src=""></script>
        $(document).ready(function() {
            $('#textbox2').val('Not Selected');
            $('#checkbox2').click(function() {
                if ($('#checkbox2').is(":checked") == true) {
                    var value1 = $(this).val();
                    $('#checkbox3').prop('checked', false);
                } else {
                    $('#textbox2').val('Not Selected');
            $('#checkbox3').change(function() {
                if ($('#checkbox3').is(":checked") == true) {
                    var value2 = $(this).val();
                    $('#checkbox2').prop('checked', false);
                } else {
                    $('#textbox2').val('Not Selected');
        <input type="checkbox" id="checkbox2" value="Male" /> Male
        <input type="checkbox" id="checkbox3" value="Female" /> Female
        <input type="text" id="textbox2" />
Posted in HTML, jQuery

You can also read...