简体   繁体   中英

How to display value in second text box by entering value in first for some condition

greeting to all, is there any way to get value in second text box, i have some filed as shown in my image, 在此处输入图片说明 if we type 90 in result text box then automaticaly the value of nor/ab field should be "Low", for 180 should be high. so we have to check over condition for 110-170(range field)...

actualy i am puzzled for the value of range field in the form of 110-170.... Any idea will be appreciated....thanks in advance...

Try to do this way:

var result = $('#result');
var sel = $('#select');

result.on('keydown keyup', function () {
   if (result.val() < 90) {
      $('option[value="low"]', sel).prop('selected', true);
    } else if (result.val() > 90) {
      $('option[value="high"]', sel).prop('selected', true);
    }
});

Demo Fiddle

var result = $("#result").val();
if(result >= 110 || result <=170){
 $("#nor").val('Normal');
}
else if(result == 90){
  $("#nor").val('Low');
}
else if(result == 180){
  $("#nor").val('High');
}

Assuming your row is wrapped in a parent div:

$('.result').change(function(){
    level = (($(this).val() < 170) ? 'low' : 'high');
    $(this).parent().find('.nor').val(level);
}

It can be improved to be a bit more readable if needed, but it should do the trick:

$("#result").on('keyup',function(){
    if($(this).val()<110){
    $("#select").val("low");
    }
    else if($(this).val()<=170){
        $("#select").val("normal");
    }
    else{
            $("#select").val("high");
    }
})

http://jsfiddle.net/YWUrR/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM