I am trying to get the value of an input element. The element is in a modal and the modal data is populated with different values depending on the button I click to open the modal.
var modalBody = document.getElementsByClassName("modal-body"); for(var i = 0; i < modalbody.length; i++) { var mac = modalBody.item(i).getElementsByTagName('div')[2].getElementById("mac-name").value; alert(mac); } error: TypeError: modalBody.item(...).getElementsByTagName(...)[2].getElementById is not a function
I also tried with document.getElementById("mac-name").value; but that returns blank
<form method="post"> <div class="modal-body"> <div class="form-group"> <label for="station-name" class="col-form-label">ID:</label> <input class="form-control" id="station-id" name="edit--id" required="" type="text" hidden=""> <input class="form-control" id="station-name" name="edit--name" required="" type="text"> </div> <div class="form-group"> <label for="profile-name" class="col-form-label">Profile:</label> <select type="text" class="form-control" id="profile-name" name="edit-profile" required=""> <option>name1</option> <option>name2</option> </select> </div> <div class="form-group"> <label for="mac-name" class="col-form-label">MAC Address:</label> <input class="form-control" id="mac-name" name="edit-mac" required="" type="text"> </div> </div> </form>