How to render new password with button in input field? PHP

I got problem,where after I hit Heslo(password) button it did what it should, but everytime resets whole page. How should I make it, that after hitting button it renders new password just in input field without reseting whole page?

this is part, where password is generated

<?php

if(!isset($_POST['generate'])){
  $password = "heslo pre edit/delete";
}else{
  $password = substr(md5(rand()), 0, 5);
}

?>

and html part for button and input

 <div class="input-group mb-3">
     <div class="input-group-prepend">
     <button class="btn btn-dark" type="submit" id="generate" name="generate">Heslo</button>
 </div>
     <input readonly="readonly" type="text" class="form-control"  name="editPassword" 
      id="editPassword" value="<?php echo $password ?>">
 </div>

enter image description here