How to type something in form input a and display it in form input b and in div c
lets assume that I enter value 100 in form input a, how can I make it to appear in form input b and div c as I type
The code below is not working properly
<script>
$(function() {
$('[name="b"]').on('change', function() {
$('[name="a"]').val($(this).val());
});
});
</script>
<input type="text" id="a" name="a" value="">
<input type="text" id="b" name="b" value=""/>
<div id="c" class="c"></div>
CodePudding user response:
Add the event listener to the input whose name is a
instead of b
:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(function() {
$('[name="a"]').on('input', function() {
$('[name="b"]').val($(this).val());
});
});
</script>
<input type="text" id="a" name="a" value="">
<input type="text" id="b" name="b" value=""/>
<div id="c" class="c"></div>
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>