Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Form run JS function onsubmit

I have a function that I want called on submission of my Laravel Form for Ajax purposes. How can I go about this where the page does not submit and reload?

This works: (but the Enter btn does not execute)

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

This does not:

<?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(); ?>
like image 820
Adrian Bartholomew Avatar asked Aug 12 '13 03:08

Adrian Bartholomew


1 Answers

<?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 could use my Enter button!

like image 94
Adrian Bartholomew Avatar answered Sep 21 '22 22:09

Adrian Bartholomew