How to Continue sending form after "e. preventDefault();"

Asked

Viewed 515 times

0

I have a code from an animated search bar, but the animation does not work together with sending the survey. I believe it is the "e. preventDefault();" that I am unable to bring the event after the animation:

<form action='/search' method='get'>
<input id="search" type="search" name="q" />
<p></p>
</form>
<script>
var form = $('form'),
search = $('#search');

form.submit(function(e) {
e.preventDefault();

search.addClass('searching').val('');

setTimeout(function() {
    search.removeClass('searching');
}, 3600);
event.currentTarget.submit(); // Com essa linha consigo enviar mas a pesquisa digitada não vai
});

    </script>
  • And what’s the problem?

  • The form works perfectly without this script, but when adding it the animation flows correctly but the queries stop working: <script> var form = $('form'), search = $('#search'); form.Submit(Function(e) { e.preventDefault(); search.addClass('Searching'). val(''); setTimeout(Function() { search.removeClass('Searching'); }, 3600); Event.currentTarget.Submit(); // With this line I can send but the typed search will not >

2 answers

1

In your code is written

event.currentTarget.submit(); // Com essa linha consigo enviar mas a pesquisa digitada não vai

But the problem wouldn’t be this other line here?

search.addClass('searching').val('');

You yourself are passing an empty value to your input, so in your request the parameter is sent empty.

  • Really, it solved :) Thank you very much!

0


You are setting the empty value with this code line:

search.addClass('searching').val('');

where . val(') refers to the value of the variable referred, i.e., (') = empty.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.