0

I'm trying to run a javascript function when the submit-button on a form is pressed, however instead of running the actual function, the form get posted and the javascript is never executed. I've made sure that the javascript is working by alerting stuff, however this particular function is broken. instead i am redirected to page saying notFoundHttpException. and for a short second, just before redirection, a message is written in the console saying: uncaught typeerror: object is not a function

{{ Form::open(array(null, null, 'onsubmit' => 'comment(this); return false;')); }}

{{ Form::hidden('codesnippet_id', $codesnippet[0]->id) }}
{{ Form::textarea('comment', null, array('placeholder'=>'comment')) }}
{{ Form::submit('comment', null, array('class'=>'comment-knapp'))}}
{{ Form::close() }}

1 Answer 1

3

I'm sure there're better solutions to this, but I always did it like this:

  1. Give the action parameter something useful (e.g. a real route/controller) in case javascript is disabled and give the form-element an id of, let's say 'yourForm'.

  2. Replace the submit button with something like this:

    <button onclick="$('#yourForm').submit(); return false;" id="formSubmit">

  3. Use JS to prevent the form from being submitted and do other awesome stuff with the data.. like this:

    $( '#yourForm' ).on('submit', function() { return false; });

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

1 Comment

Thnx! Usually do it this way as well, however i wanted to know if there was a way to do it using nothing but post! Still, thnx for taking time to answer! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.