0

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?

Jessy642
  • 67
  • 8
  • Can you rephrase the question? It seems like you want a function to run if some value in database is set. Is that it? – Shreesh Kulkarni Sep 16 '22 at 10:40
  • Yes, thats it :) If that's to complex the other options would be: "Check if in the loaded form a checkbox is already checked on page load - If yes then run the function" - I clarified it in the main post now – Jessy642 Sep 16 '22 at 10:43
  • you just check the current value from your onload function and do something with it. – chovy Sep 16 '22 at 10:46
  • Just do your check and do what you want. You have a not existing problem. Just code your check. – Marc Sep 16 '22 at 10:56
  • Thank you :) I am sorry about that I am new to that theme, would you be so nice and help me with the code? – Jessy642 Sep 16 '22 at 11:03

0 Answers0