admin管理员组文章数量:1325137
I have two inputs(number).
How can I duplicate data from first to second and back?
For example, I'll set some value in first input and in second input I get same value and if I set same value in second input I want to get same value in first input.
I think it must be something like that
<div class="first">
<input type="text" id="email">
</div>
<div class="second">
<input type="text" id="name">
</div>
<div id="slider"></div>
<script>
$('#email').change(function(){
$(this).val($('#name').val());
});
('#name').change(function(){
$(this).val($('#email').val());
});
$('#slider').slider();
</script>
/
When I'm trying to put smth in slider() function I get error in console (slider function doesn't exist)
Thanks.
I have two inputs(number).
How can I duplicate data from first to second and back?
For example, I'll set some value in first input and in second input I get same value and if I set same value in second input I want to get same value in first input.
I think it must be something like that
<div class="first">
<input type="text" id="email">
</div>
<div class="second">
<input type="text" id="name">
</div>
<div id="slider"></div>
<script>
$('#email').change(function(){
$(this).val($('#name').val());
});
('#name').change(function(){
$(this).val($('#email').val());
});
$('#slider').slider();
</script>
https://jsfiddle/Frunky/hzh9zwfo/4/
When I'm trying to put smth in slider() function I get error in console (slider function doesn't exist)
Thanks.
Share Improve this question edited Feb 25, 2017 at 21:11 Frunky asked Feb 25, 2017 at 20:00 FrunkyFrunky 3851 gold badge6 silver badges15 bronze badges 1- Show us what you've tried so far – technophobia Commented Feb 25, 2017 at 20:03
2 Answers
Reset to default 6You almost had it...
Try this:
$('#email').keyup(function (){
$('#name').val($(this).val()); // <-- reverse your selectors here
});
$('#name').keyup(function (){
$('#email').val($(this).val()); // <-- and here
});
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="first">
<input type="text" id="email">
</div>
<div class="second">
<input type="text" id="name">
</div>
Building on @technophobia 's answer, if you want them to update live, try this:
$('#email').keyup(function(){
$('#name').val($(this).val());
});
$('#name').keyup(function(){
$('#email').val($(this).val());
});
本文标签: javascriptMake two input with same data valueStack Overflow
版权声明:本文标题:javascript - Make two input with same data value? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742173010a2427065.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论