I have the following situation. I am using tabs to manage different contents within my web page, where there is a form in each one of them.
What is happening to me is that when I want to capture the form id of the active tab, it always takes the one of the first tab. I capture the id when performing an onChange event on an input file . Here is the code to see if you can help me.
Thanks.
Html from tab 1
<form class="form-signin" id="idfrom" method="post" action="">
<label><strong>Subir Documentos (Solo JPG, JPGE, DOC, PDF XLS)</strong></label>
<input type="file" name="uploadfile" id="uploadfile">
</form>
html from tab 2
<form class="form-signin" id="fidcoment" method="post" action="">
<label><strong>Subir Documentos (Solo JPG, JPGE, DOC, PDF XLS)</strong></label>
<input type="file" name="uploadfile" id="uploadfile">
</form>
JavaScript code
$(":file").change(function(){
var idFormula = $("form").attr('id');
});
The result of idFormula is always idfrom
I made a little example with tab which provides bootstrap:
The change event on the file type field would be like this:
Most likely the library you use for tabs only hides and does not remove the html content when you switch tabs. So this is the problem:
Here the selector chooses the first
<form>
one it finds, which is always the one from tab 1.Try this:
The selector chooses the
<form>
parent<input>
whose event was just fired.this could help you!