Home>

Environment: ruby ​​on rails 6.0.3
I didn't see any error when I looked at the verification tool, and I could not confirm that it is working.
I thought that it works because the following source is listed in the verification tool Source, but I honestly do not know what to do because there is no error.

$(function() {
    $('input[id="page_page_div_contact us"]').change(function() {
        var val = $(this).val();
        if (val == 1) {
            $("#contact_title").prop('disabled', true);
        }
    });
});

<%= form.radio_button :page_div, :notice, checked: "checked" %>
<%= form.label: Notice, class: "page_div_label" %>


<%= form.radio_button :page_div, :privacy policy %>
<%= form.label: privacy policy, class: "private_label" %>


<%= form.radio_button :page_div, :Terms of use %>
<%= form.label: Terms of use, class: "page_div_label" %>


<%= form.radio_button :page_div, :contact %>
<%= form.label: contact us, class: "page_div_label" %>

<%= form.text_field :title, id:'contact_title' %>
  • Answer # 1

    If no error appears,
    How far is it working by displaying the log at an appropriate place?
    Is the content of the variable at that time as intended? If you check
    You can find it.

    $(function() {
        $('input[id="page_page_div_contact us"]').change(function() {
            var val = $(this).val();
    console.log(val);
    console.log("1");
            if (val == 1) {
    console.log("2");
                $("#contact_title").prop('disabled', true);
            }
    console.log("3");
        });
    });

  • Answer # 2

    If there is no error, it is working?
    Debug at the appropriate breakpoint or console

    If you add a strange character string to id, it will be blurred, so it is better to stop if you want to reduce the risk