Laravel Form launches onsubmit JS function

I have a function that I want to call when presenting my Laravel Form for Ajax purposes. How to do this if the page does not submit and does not reload?

This works: (but Enter btn fails)

<?php echo Form::open(); ?> <?php echo Form::button('Search', array('id'=>'searchbtn', 'class'=>'button radius right', 'onclick'=>'myFunction(this.form)')); ?> <?php echo Form::close(); ?> 

It does not mean:

 <?php echo Form::open(array('onsubmit' => 'myFunction(this)')); ?> <?php echo Form::submit('Search', null, array('id'=>'searchbtn', 'class'=>'button radius right')); ?> <?php echo Form::close(); ?> 
+4
source share
1 answer
 <?php echo Form::open(array(null, null, 'onsubmit' => 'myFunction(this); return false;')); ?> <?php echo Form::submit('Search', null, array('id'=>'searchbtn', 'class'=>'button radius right')); ?> <?php echo Form::close(); ?> 

Yayy. Now I can use my "Enter" button!

+3
source

Source: https://habr.com/ru/post/1496485/


All Articles