ok avevo fatto un cappellotto sulla funzione
comunque ho anche spostato la funzione sull'onsubmit del form come consigliato in altro topic