How to send form data with onChange event to php

2

Good morning, someone can help me with the following problem, I want to send data from two fields, one of type text and another of type select option and I want when I click on the selection do the post. Here is my code.

HTML

<form method="post" action="">

            <input type="text" name="nome" onChange="Enviar(this.value);" >
            <select name="sexo" onchange="">
                <option value="">selecionar...</option>
                <option value="M">M</option>
                <option value="F">F</option>
            </select>

        </form>

Javascript

<script>
            function getState() {
                $.ajax({
                    method: "post",
                    url: "pag.php",
                    data: $("#form").serialize(),
                });
            }
        </script>

And on page pag.php

PHP

But it does not work out

    
asked by anonymous 13.07.2016 / 11:36

2 answers

1

Hello, you are not calling the function described. You should add the function to your "onchange" selection.

<select name="sexo" onchange="getState()">
    
13.07.2016 / 13:45
0

You can call the function like this too:

$(document).on('change', "[name='sexo']", function(){
   getState();
});
    
13.07.2016 / 14:19