Reputation: 5450
UPDATE: my own mistake. I should have used document.getElementById("auxInputImageForm")
Thank you for every comment.
I have 2 forms in my HTML (auxInputImageForm
and myFormID
):
<div class="row">
<div class="col-md-5" style="padding:0px;"></div>
<div class="col-md-2" style="background-color:red; padding:0px;">
<div id="methodDiv">
<form id="auxInputImageForm">
<input class="btn btn-default" type=file name=file style="width:190px; margin-top:5px;padding-left:0px; padding-right:0px;">
<input id="uploadBtn" class="btn btn-primary btn-sm" type=submit value=Upload style="margin-top:5px; margin-left:60px">
</form>
</div>
</div
<div class="col-md-5" style="padding:0px;">
<form id="myFormId">
<input class="btn btn-default" type=file name=file style="width:190px; margin-top:5px;padding-left:0px; padding-right:0px;">
<input id="uploadBtn" class="btn btn-primary btn-sm" type=submit value=Upload style="margin-top:5px; margin-left:60px">
</form>
</div>
</div
However, document.forms
only returns myFormID
. Below is the console.log(document.forms):
Also, I tried document.getElementById("auxInputImage")
, but it returns null.
Is there a different javascript function I can use or is there something wrong with the code? Any help is much appreciated. Thank you
Upvotes: 0
Views: 76
Reputation:
The issue lies in your html, have a closer look at this part:
</form>
</div>
</div <!-- not closed, missing (>) -->
This is repeated twice in your current post. Correct this and document.forms
works as expected.
console.log(document.forms.length)
<div class="col-md-2" style="background-color:red; padding:0px;">
<div id="methodDiv">
<form id="auxInputImageForm">
<input class="btn btn-default" type=file name=file style="width:190px; margin-top:5px;padding-left:0px; padding-right:0px;">
<input id="uploadBtn" class="btn btn-primary btn-sm" type=submit value=Upload style="margin-top:5px; margin-left:60px">
</form>
</div>
</div>
<!-- added (>) -->
<div class="col-md-5" style="padding:0px;">
<form id="myFormId">
<input class="btn btn-default" type=file name=file style="width:190px; margin-top:5px;padding-left:0px; padding-right:0px;">
<input id="uploadBtn" class="btn btn-primary btn-sm" type=submit value=Upload style="margin-top:5px; margin-left:60px">
</form>
</div>
Upvotes: 1