In my view, i have many input, how can i insert input first to another input in keyup, this is my code :
$(document).ready(function()
{
$("#costForAll").keyup(function()
{
$("#cost").val($("#costForAll").val());
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div>
<input id="costForAll">
</div>
<form>
<tr>
<td>
<input id="cost" type="number" >
<input id="cost" type="number" >
<input id="cost" type="number" >
<input id="cost" type="number" >
<input id="cost" type="number" >
<input id="cost" type="number" >
<input id="cost" type="number" >
<input id="cost" type="number" >
<input id="cost" type="number" >
</td>
</tr>
</form>
this code working for me, but just on first (id="cost")
please help me, thank's all
CodePudding user response:
You have to use id's unique but still you can update values like this
$(document).ready(function()
{
$("#costForAll").keyup(function()
{
$("input[id=cost]").each((i,n)=>{
n.value = $("#costForAll").val();
})
});
});