1

I want to create a Confirm message if the user klicks on my submit button. I've created the submit button with the Laravel Form package. Well, I don't really work with javascript and haven't found an answer for that.

Thats my submit Form:

{!! Form::submit('Delete', ['class' => 'btn btn-danger']) !!} 

I tried something like this:

<script>

  function ConfirmDelete()
  {
  var x = confirm("Are you sure you want to delete?");
  if (x)
    return true;
  else
    return false;
  }

</script>

{!! Form::submit('Delete', ['class' => 'btn btn-danger', 'onsubmit' => 'return ConfirmDelete()']) !!}

But this haven't worked. Can anyone help me there?

7
  • Do you see any error in console ? Care to elaborate haven't worked! Commented Apr 12, 2016 at 7:40
  • no everything seems fine Commented Apr 12, 2016 at 7:40
  • Can you share executable demo/snippet or jsfiddle ? Also share the parsed HTML Commented Apr 12, 2016 at 7:41
  • Problem Solved! look into my question update :) Commented Apr 12, 2016 at 7:45
  • But is there a way to change the style of the confirm box? it's still this old html box. Maybe a bootstrap way? Commented Apr 12, 2016 at 7:52

1 Answer 1

1

Instead of using inline-event onsubmit you could add an extra class test-form then attach submit event to it in js code.

Adding class :

{!! Form::open(['action' => ['Test\\TestController@destroy', $thread->id], 'method' =>
    'delete', 'class' => 'test-form' ]) !!}

Attaching submit event :

$('.test-form').submit(function(e) {
    e.preventDefault();

    if ( confirm("Are you sure you want to delete?") ) {
        $(this).submit();
    }
});

Hope this helps.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.