Blue Minnie
Blue Minnie

Reputation: 231

Addition/subtraction to a specific value to user input

Is it possible to have a textbox where the user will input a number and in another textbox, which will automatically add 5 to the value of the first textbox and subtract 5 to the value in the third textbox?

For example:

User input: 10

2nd textbox: 15

3rd textbox: 5

Please help

Upvotes: 2

Views: 511

Answers (2)

Vishvadeep singh
Vishvadeep singh

Reputation: 1663

you can find solution Link.

HTML Part

<input type="number" id="input1">
<input type="number" id="input2">
<input type="number" id="input3">

JS Part

$('#input1').bind('click keyup', function(event) {
   $('#input2').val(parseInt(this.value)+5);
   $('#input3').val(parseInt(this.value)-5);
})

Upvotes: 0

N3R4ZZuRR0
N3R4ZZuRR0

Reputation: 2422

You can do it like this:

<input type="text" id="input1" onkeyup="setValues(this.value);">
<input type="text" id="input2">
<input type="text" id="input3">

<script type="text/javascript">
function setValues(value){
    document.getElementById('input2').value = (parseInt(value)+5);
    document.getElementById('input3').value = (parseInt(value)-5);
}
</script>

Upvotes: 2

Related Questions