G
G
Good Samaritan2018-02-05 11:58:36
JavaScript
Good Samaritan, 2018-02-05 11:58:36

Is it real at all?

I am new to js.
I need to substitute the value from the input in the action of the form, I try like this:

<form action="/search/node/document.getElementById('search').value" method="get">
                    <span class="icon"><i class="fa fa-search"></i></span>
                    <input type="search" id="search" placeholder="Поиск..." />
                        <input type="submit">
                    </form>

It does not work
How to implement it correctly so that it works?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Tsymbal, 2018-02-05
@djamali

more correctly like this:

jQuery(document).ready(function($){
  $('#searchform [type="submit"]').on('click', function(e){
    e.preventDefault();
    $(this).closest('form').attr('action', '/search/node/' + $('#search').val()).submit();
  });
});

<form>And don't forget to add id="searchform" to the form ( ), otherwise the code will work when submitting any form on the site.
And since the author of the question is new to JS, it is worth mentioning that this code works on the jQuery framework, which must be included before calling this code. And this code - immediately after the output of the form code, wrapping it in <script>...</script>.

D
Dmitry Kim, 2018-02-05
@kimono

$('button[name=fake-submit]').on('click', function(){
    $(this).closest('form').attr('action', '/search/node/' + $('#search').val()).submit();
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question