Reputation: 13
I was wondering if someone can help me develop this in Jquery (mobile):
I want to make two text fields, in the first one you have to enter a number and in the other one I want to see a result. I mean something like this:
example 1:
textfield 1: 220 till 285 < input
textfield 2: 1 < result
example 2:
textfield 1: 286 till 350 < input
textfield 2: 2 < result
example 3:
textfield 1: 351 till 415 < input
textfield 2: 3 < result
This must happen automatically and not with pressing a button, etc., like this method
UpdATE! What i mean is more a range like this: input: for example the numberrange 220 till 285 will result in 1. 286 till 350 in 2. 351 till 415 in 3. So all the numbers between for example 351 - 415 must has 3 as output
Upvotes: 0
Views: 2536
Reputation: 616
Simply use the keyUp event provided by jquery:
html
<input type="text" id="input" />
<input type="text" id="output" />
js
$('#input').keyup(function() {
$('#output').val($('#input').val().substring(0,1));
});
EDIT
You can check the input with simple if-conditions:
$('#input').keyup(function () {
var value = $('#input').val();
if(value >= 220 && value <= 285)
$('#output').val(1);
else if(value >= 286 && value <= 350)
$('#output').val(2);
else if(value >= 351 && value <= 415)
$('#output').val(3);
else
$('#output').val("");
});
Upvotes: 1