Automatically start JS on page load IF

Viewed 30

I would like to know how one of this option would work - doesn't matter which one.

Option 1: If its possible to make a JS automatically work if a value is (lets say in id="field2") stored in database and loaded.

Or option 2: "Check if in the loaded form a checkbox is already checked on page load - If yes then run the function"

What I found for automatically make a function work when page is loaded is (Source: How to run a function when the page is loaded?):

<script type="text/javascript">
document.addEventListener('DOMContentLoaded', function() {
alert("Ready!");
}, false);
</script>

But I want that only if value A (example..) is stored/loaded from database makes the following JS code work on page load.

<script type="text/javascript">
document.getElementById("field1").style.color = "red";
</script>

Does someone know how to make that work?

0 Answers
Related