How to send form data with onChange event to php

Asked

Viewed 2,482 times

2

Good morning guys, can anyone help me with the following problem, i want to send data of two fields, one of type text and the other of type select option and I want when I click on select to do post. there 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.php

PHP

But it’s not working

2 answers

1

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

<select name="sexo" onchange="getState()">

0

You can call the function so too:

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

Browser other questions tagged

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