If you run the code, the second form is influenced by the first one and does not take the data for itself. Of course this is a flaw in my jQuery. The first form works perfectly, the second one always takes the last value sent by the first one.
I need each one to send their data regardless of the estado
class if it is repeated in both forms. This information is then sent to an Ajax that will query the database.
These forms share the same page and have the same classes by simply exchanging the form id. What it seems is that it always executes the form that comes first and then stops executing just because the selects have the same class.
Can you help me?
function buscar_cidades(e){
var formid = $(e).closest("form").attr("id");
var estado = $(".estado").val();
alert(estado);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script><formid="fpf" class="" method="post" action="">
<select name="estado" class="estado" onchange="buscar_cidades(this)">
<option value=""></option>
<option value="000001">AC</option>
<option value="000002">AL</option>
<option value="000003">AM</option>
</select>
</form>
<form id="fpj" class="" method="post" action="">
<select name="estado" class="estado" onchange="buscar_cidades(this)">
<option value=""></option>
<option value="000001">AC</option>
<option value="000002">AL</option>
<option value="000003">AM</option>
</select>
</form>