Search code examples
google-chromegreasemonkeytampermonkey

How do I change the input attributes of a text field using GreaseMonkey/TamperMonkey?


How do I remove the readonly attribute from this input field?

<input class=" calendar_field" id="zoom_meeting_room[scheduled_on]" name="zoom_meeting_room[scheduled_on]" readonly="readonly" type="text" value="2020-11-07 12:08">

Thank you


Solution

  • Here is an example:

    document.querySelector('#zoom_meeting_room[scheduled_on]').removeAttribute('readonly');
    

    or

    document.getElementById('zoom_meeting_room[scheduled_on]').removeAttribute('readonly');
    

    In order to avoid errors

    const input = document.getElementById('zoom_meeting_room[scheduled_on]');
    if (input) { input.removeAttribute('readonly'); }
    

    or

    const input = document.getElementById('zoom_meeting_room[scheduled_on]');
    input && input.removeAttribute('readonly');
    

    You can also set it to false

    const input = document.getElementById('zoom_meeting_room[scheduled_on]');
    if (input) { input.readOnly = false; }
    

    or

    const input = document.getElementById('zoom_meeting_room[scheduled_on]');
    if (input) { input.setAttribute('readonly', false); }