Potresti semplicemente creare una funzione e associarla all'evento onclick del pulsante