Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

How to set readonly attributes to input with checkbox

1611271369

Edited 1611271398
Hi, Is it possible to set an input as readonly when a checkbox is checked? I know that there is action button and onClick function but can we change attributes other than "name" and "value" ? Thanks
1611290809
Finderski
Plus
Sheet Author
Compendium Curator
The way I would handle that is toggle between the input and a named span. So, if the checkbox is not checked, display the input <input type="text" name="attr_myinput" /> And if the checkbox is checked, then hide the input and display something like this: <span name="att_myinput"></span>
1611294106

Edited 1611294591
vÍnce
Pro
Sheet Author
Here's a basic example that swaps an editable input with a read-only span; <!--HTML--> Edit/Lock: <input class="edit" type="checkbox" name="attr_edit_flag" value="1" /> <div> Foo 01: <input type="number" name="attr_foo_01" value="10" /> <span class="readonly" name="attr_foo_01"></span> </div> <div> Foo 02: <input type="number" name="attr_foo_02" value="10" /> <span class="readonly" name="attr_foo_02"></span> </div> <!--CSS--> input.sheet-edit[type=checkbox]:not(:checked) ~ div > input {display:inline-block;} input.sheet-edit[type=checkbox]:not(:checked) ~ div > input + span.sheet-readonly {display:none;} input.sheet-edit[type=checkbox]:checked ~ div > input {display:none;} input.sheet-edit[type=checkbox]:checked ~ div > input + span.sheet-readonly {display:inline-block;}
1611295231
GiGs
Pro
Sheet Author
API Scripter
This is the way. Personally, I'd use a readonly input instead of a span, so the appearance changes very little (just gets the grey shading of readonly).
Thank you, I used that way and it works perfectly !