1

I have the following button

<button type="button"
  title="Previous value:"
  ***onload="test()"***
  class="btn btn-warning mb-2" style="padding: 4px 8px 4px 8px; border-radius: 1rem;">
 <i class="fas fa-exclamation-triangle text-white"></i>
</button>

Which I want it when it loads to call the test() function

function test() {
    console.log("I am in");
}

in reality this function will be creating a popover. But it doesnt seem to be calling the function. (No, onclick or hover is not helping me.)

Any suggestions, ideas how to achieve that?

Many thanks in advance.

Chris Tsag
  • 49
  • 1
  • 6
  • Hey Chris, whith the onload event on a button, do you really want to create your popover immediately when the button is rendered on the page or when the user does a specific action with this element ? – Philippe Sep 19 '21 at 17:44
  • Hi @Philippe, I really want to display the popover when the page is loaded. So immediately, because I use it as notification icon next to all the altered values of my page. – Chris Tsag Sep 27 '21 at 08:50
  • Okay, so why do you focus on this button ? ;) You'd better listen the `window` `onload` event. https://stackoverflow.com/a/588048/4698373 – Philippe Sep 27 '21 at 09:37

3 Answers3

1

onload event is only supported on these HTML tags:

<body> <iframe> <img> <input type="image"> <link> <script> <style>

take a look at: HTML onload attribute

Erfan Yeganegi
  • 311
  • 1
  • 9
0
    <button type="button" title="Previous value:" onclick="test()" class="btn btn-warning mb-2" style="padding: 4px 8px 4px 8px; border-radius: 1rem;">
 <i class="fas fa-exclamation-triangle text-white"></i>
</button>

<script>

function test(){
    //alert("test");
    console.log("I am in");
}
</script>`enter code here`
Engr Saddam Zardari
  • 1,057
  • 1
  • 14
  • 27
0

Try using Ajax and call the function by id or class by button click.