Problem with Js and the onload event

0

I'm trying to make an alert on a function load with the onload event. It's easy but it does not work because I'm not. Code:

function inicia(){
  alert("hola");
}
<body onload="inicia()">
    <table style="width:50%"  border="1" text-align="right">
      <tr>
        <th>Producte</th>
        <th>Preu</th>
        <th>Quantitat en magatzem</th>
        <th>Compra</th>
      </tr>
      <tr>
        <td>Televisor</td>
        <td align="right">500</td>
        <td align="right" id="quantitat_televisors"></td>
        <td> <input type="text" id="compra_televisors" name="televisors" value="0"></td>
      </tr>
      <tr>
        <td>Nevera</td>
        <td align="right">400</td>
        <td align="right" id="quantitat_neveres"></td>
        <td><input type="text" id="compra_neveres" name="neveres" value="0"></td>
      </tr>
    </table>
        <br/>


    <input type="button" value="Factura" onclick="omple_cookies_compra();">
        <input type="button" value="Reomple magatzem" onclick="reomple();">
        <input type="button" value="Esborra cookies" onclick="esborraCookies();">
    </body>
    
asked by Oriol 12.11.2017 в 17:54
source

1 answer

0

Check that you have an instruction so that in your html either in the head or in the body:

<script src="ruta/tuarchivo.js"></script>

the route = your path to the file that should be well written , I think that's where you have the problem.

your file = the name of the well-written js file and do not forget the .js

Then in your file.js should be the function:

function inicia(){
  alert("hola");
}
    
answered by 12.11.2017 в 18:16