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

Is it possible to set default value on an auto-calculating field?

1409207560
Dan W.
Sheet Author
Hi Wizards, New to CSS. I'm fiddling around with a sheet and what I'd like to do is set an input field (type="number") to a default value. That's easy enough to do, but I want that default value to change depending on if a checkbox is checked or not. Also, I still want the user to be able to modify the value for other adjustments that may happen in their game, so I don't think it can be set disabled="true". This is basically an error range on a skill and that error range changes if the character is trained (has ranks) in the skill or not. Possible?
1409215139
Lithl
Pro
Sheet Author
API Scripter
Does the player need to be able to access the attribute in a macro under normal circumstances?
1409249898
Dan W.
Sheet Author
No, we don't have any such macro's in my game. The intention on my part is to reduce the amount of time needed for data entry when creating a new character.
1409254123
Lithl
Pro
Sheet Author
API Scripter
In that case, you could try using the checkbox to show/hide two different number inputs with different defaults. <input type="checkbox" name="attr_toggle-check" value="1" /> <input type="number" name="attr_field-1" value="5" min="1" max="10" /> <input type="number" name="attr_field-2" value="15" min="10" max="20" /> input[name=attr_toggle-check]:checked ~ input[name=attr_field-1], input[name=attr_toggle-check]:not(:checked) ~ input[name=attr_field-2] { display: none; } input[name=attr_toggle-check]:not(:checked) ~ input[name=attr_field-1], input[name=attr_toggle-check]:checked ~ input[name=attr_field-2] { display: inline; } This would show field-1 when the checkbox is not checked, and show field-2 when the checkbox is checked. I believe one or more of the oWoD sheets does something similar to swap out roll buttons.
1409347087

Edited 1409403233
Dan W.
Sheet Author
Brian, Many thanks for that input! If I put the checkbox element into the same <td> along with the two attribute fields, that works when (un)checking the box. However, the actual checkbox I want to use is in a different <td> of a table row so they aren't siblings. I've looked through different selection operators and tried a few things but I've been unable to hit on a working strategy. The checkbox is the 0th td of the table row and the two number input fields are in the 7th if that helps/matters. <tbody> <tr> <td> <!--input name="attr_acrobatics_origin" value="0" type="checkbox"/--> <input type="checkbox" name="attr_acro_toggle-check" value="1" class="sheet-origin"/> </td> <td>Acrobatics</td> <td> <input name="attr_acrobatics_bonus" value="@{acrobatics_ranks}+ @{acrobatics_attr_mod}+ @{acrobatics_misc_mod}+ @{acrobatics_temp_mod}" disabled="disabled" type="number"/> </td> <td> <input name="attr_acrobatics_ranks" value="0" type="number"/> </td> <td> <input name="attr_acrobatics_attr_mod" value="@{DEX_mod}" disabled="disabled" type="number"/> </td> <td> <input name="attr_acrobatics_misc_mod" value="0" type="number"/> </td> <td> <input name="attr_acrobatics_temp_mod" value="0" type="number"/> </td> <td> <input type="number" name="attr_acrobatics_error" value="1" min="0" max="20"/> <input type="number" name="attr_acrobatics_error_untrained" value="3" min="3" max="20"/> </td> <td> <input name="attr_acrobatics_threat" value="20" type="number"/> </td> <td> <button type="roll" value="/roll 1d20 + [[@{acrobatics_bonus}]] Acrobatics Check for @{character_name}" name="roll_acrobatics"/> </td> <td> <button type="roll" value="/gmroll 1d20 + [[@{acrobatics_bonus}]] Acrobatics Check for @{character_name}" name="roll_acrobatics_gm"/> </td> </tr>
1409353354
Lithl
Pro
Sheet Author
API Scripter
With only CSS, siblings (or newphews) are your only option. However, you could potentially make the elements siblings in the DOM and use positioning (relative or absolute) to move the checkbox where you want it.
1409357312
Dan W.
Sheet Author
Ah, well so much for the easy path. Cheers Brian, at least I'm armed with the right information rather than flailing at it uselessly .... :-P Oh, by the way -- what kind of tags/keywords did you use to format your xml/css so that it came out looking nicely indented rather than hard to read like mine?
1409396989
Lithl
Pro
Sheet Author
API Scripter
Click the Formatting button at the top-left of the reply box and select Code.