Checked Checkbox Autofill Question with sample code - help request

112 views
Skip to first unread message

Christian Kocmick

unread,
Nov 3, 2022, 8:06:22 PM11/3/22
to Autofill Extension
I am trying to fill in a text box based on the checked, numbered items list on a website.

So far, this is what I have. It works on jsfiddle.net (Big IF) I don't use the actual identifier of the checkbox. For example, cbNo1-33.1 is the id of a checkbox.

Each checkbox identifier has a unique word dash number. so when I write the identifier into javascript and jQuery, I get an error. Is there a way around this issue?

//copy and paste into jsfiddle
//HTML

<label>Skill Overall</label>
<input type="text" size="40" id="txtComment" name="txtComment"/>

<br /><br />
<label>Skill Number and Name of the Skill</label>
<input type="checkbox" id="cbNo1" />

// Javascript + JQuery/jquery-3.4.1

$(document).ready(function(){
    $("#cbNo1").on("click", function () {
        var ibComment;
        if ($(this).is(":checked")) {
            ibComment = $('[name="ibComment"]').val();
            $("#txtComment").val("CS Comment what they missed").prop("readonly", false);
        } else {
            $("#txtComment").val("").prop("readonly", false);
        }
    });
});


Christian Kocmick

unread,
Nov 3, 2022, 8:24:06 PM11/3/22
to Autofill Extension
I found the answer is to escape the special characters with "\\" as shown below.

$(document).ready(function(){
    $("#cbNo1\\-1\\.1").on("click", function () {

        var ibComment;
        if ($(this).is(":checked")) {
            ibComment = $('[name="ibComment"]').val();
            $("#txtComment").val("CS Comment what they missed").prop("readonly", false);
        } else {
            $("#txtComment").val("").prop("readonly", false);
        }
    });
});

Christian Kocmick

unread,
Nov 3, 2022, 8:40:04 PM11/3/22
to Autofill Extension
Still not working. jQuery is not reading the checkboxes and is not filling in the text "CS Comment what they missed."

Any suggestions?
Reply all
Reply to author
Forward
0 new messages