1
If you execute the code you will see that 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 always takes the last value sent by the first.
I need each of you to submit your class-independent data estado
repeat in both forms. This information is later sent to an Ajax that will make a query in the database.
These forms divide the same page and have the same classes by simply changing the form id. What it seems is that it always executes the form that comes first and then stops executing precisely 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>
<form id="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>
You are going to fetch the value selected by name... Since you have two select with the same name, it will give hole. You have to get the select belonging to the form
– CesarMiguel