Create action on an html button

Asked

Viewed 1,610 times

2

I’m new to Web development and I came across the following problem. I have an input text and an html button and I need to create an action that by clicking the button, a function is called and in the function, I will make the proper manipulations. Follow my code below.

<!-- FILTRO FLUTUANTE -->
    <div id="mws-themer">
        <div id="mws-themer-hide"></div>
        <div id="mws-themer-content">
            <form action="fornDetails.php">
                <div class="mws-themer-section">
                    <form action="" name="myForm" id="myForm" style="padding: 0; margin: 0;" method="POST">
                        <input type="submit" name="edtMFIR" id="edtMFIR" value="filtrar" class="mws-textinput error">
                    </form>
                </div>

                <div class="mws-themer-separator"></div>

                <div class="mws-themer-section">
                    <button class="mws-button red small" id="mws-themer-sendfilterPCD">Filtrar</button>           
                </div>
            </form>
        </div>
    </div>  

How to solve the problem?

In addition to HTML, there are php and javascript codes.

  • Do you have any knowledge about Jquery ?

  • No knowledge :/

1 answer

1


Very simple.

Sem Jquery:

    var btn= document.getElementById('id-do-botao');
        btn.addEventListener('click', function(e){
 // função aqui
});    

With Jquery:

$("#id-do-botao").on("click", function(e){
    // função aqui
});

I hope I’ve helped.

A simple example to help.

var btn = document.getElementById("btn");
btn.addEventListener('click', function(e){
  alert("botao clicado");
});
<button id="btn"> Clique aqui </button>

  • <script type="text/javascript" src=".. /js/botao.js"></script>

  • Yes, I recommend referencing at the end of the page

  • If my answer is right and has helped you, mark it as the right one, to help me, and show other users in the community that the question is closed

  • It hasn’t worked out yet :/

  • What is going wrong ?

  • For testing purposes, I tried to make my button call an internet page, for example, from google. var btn= Document.getElementById('mws-Themer-sendfilterPCD'); btn.addeventlistener('click', Function(){ window.location.href="http://www.google.com"; });

  • I edited the answer, take a look and try now

Show 2 more comments

Browser other questions tagged

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