my page.php
contains div id="container"
with id="input"
which default type is input type="text"
:
<div class="container">
<div class="row">
<div class="col-75">
<div id="container">
<input type="text" id="input" value="" name="password">
</div>
<input type="submit" value="OK" id="logBtn">
</div>
</div>
</div>
I want to change input type="text"
to input type="password"
for same input id="input"
with receiving of value textToPassType(1)
:
function textToPassType(val1){
if (val1 == 1){
document.getElementById('input').type = 'password';
} else if (val1 == 0){
document.getElementById('input').type = 'text';
}
}
This way works only if I call this function included to page.php
, but if use it in external document: <script type="text/javascript" src="myjs.js"></script>
method does not works. So, I'm looking for some correct method to change input type dynamically and keep same id name from external myjs.js
to my page.php