Skip to content
Advertisement

javascript – laravel reset form

My form reset button doesnt reset my form. I added a class for my dropdowns to be hidden unless theres a change in select. The current behavior is clicking the reset button will only reset its values but doesn’t hide the supposed to be hidden dropdowns.

my reset button

{!! Form::reset('Reset', ['class' => 'btn btn-primary', 'id' => 'btn-click']) !!}

script i used

$('form').reset(function (event){
      $(document).ready(function(){
       $("#btn_click").click(function(){
       $(".dropdown").addClass("no-display");
    });
    });

Can’t find any docu about resetting a form with laravel can anyone help

Advertisement

Answer

Try this:

$(document).ready(function() {
    $("#btn_click").click(function() {
       $(".dropdown").addClass("no-display");
    });
});     

This code will execute once the document is ready, meaning it has been loaded, then it will set a click event handler for #btn_click which when clicked will add no-display class to the dropdown.

Note: There is no event handler named as reset as you have written here:

$('form').reset(function (event){
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement