Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make two input with same data value?

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.net/Frunky/hzh9zwfo/4/

When I'm trying to put smth in slider() function I get error in console (slider function doesn't exist)

Thanks.

like image 359
Frunky Avatar asked Oct 20 '25 17:10

Frunky


1 Answers

You 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.com/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>
like image 92
technophobia Avatar answered Oct 22 '25 07:10

technophobia



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!