Reputation: 33
can somebody give me recomendation how to copy textbox value to another many texbox. So far i tried : Document.getelementbyid but not work when textbox with same ID.
Or anyone know how to copy controller post data?
Upvotes: 0
Views: 220
Reputation: 2177
Improving on dbramwell answer you can use copy button to do so
var copyValues = function(){
var whatToCopy = document.getElementById("copyMe").value;
var inputs = document.querySelectorAll('input')
inputs.forEach(function(input) {
input.value = whatToCopy
});
}
Copy this
<input id="copyMe"/>
<br>
Into
<input class="copyTo" />
<input class="copyTo" />
<input class="copyTo" />
<button onclick="copyValues()">Copy</button>
Upvotes: 0
Reputation: 1326
Use document.querySelectorAll
function myFunction(val) {
var inputs = document.querySelectorAll('input')
inputs.forEach(function(input) {
input.value = val
});
}
<input type="text" name="txt" value="Hello" onkeyup="myFunction(this.value)">
<input type="text" >
<input type="text" >
<input type="text" >
<input type="text" >
Upvotes: 4