function btn() {
window.location.href = "index.html";
var precioP = document.getElementById('precioP').value;
var nombreP = document.getElementById('nombreP').value;
if (precioP == "" || nombreP == "") {
alert("achu, los datos son obligatorios achu!");
return false;
}
}
<div class="index">
<form action="alta.php" method="GET">
<FIELDSET>
<center>
<LEGEND><b>Alta producto</b></LEGEND>
<hr><br><br>
<label>Nombre del producto</label><br><br>
<input type="text" name="nombreP" id="nombreP"><br><br>
<label>Precio producto</label><br><br>
<input type="number" step="0.01" name="precioP" id="precioP"><br><br>
<button style="width:50%" id="btn" onclick="btn()">GUARDAR DATOS</button>
</center>
</FIELDSET>
</form>
</div>
When I run it and I do not write anything, I do not get the alert, it's as if they have not connected properly.