如何在php或html中的值输入后自动显示类别


how to auto show the category after value entry in php or html?

我有一个输入字段假设权重和另一个字段,它将在不提交的情况下显示基于权重输入的类别。就像如果我在下一个字段中输入9,它会显示2。类别是如果weight<5然后是1,5-10然后是2,10-15然后是3,依此类推。如何做到这一点请帮忙。

试试这个。。。。。。。。。。。。

<script type="text/javascript">
function chk(val)
{
    if(val<5)
        document.getElementById("scd").value = "1"
    if(val>=5 && val<=10)
        document.getElementById("scd").value = "2"
}
 </script>
     <input type="text" id="fst" onchange="chk(this.value)">
     <input type="text" id="scd">

试用jquery-

<input type="text" id="sample">

在脚本中-

$('#sample').on('keyup change', function() {
     var val = $(this).val();
     if (val < 5) {
        $('yourselect').val(1);
     } else if () {} .... //so on
})

试试这个

 $options = array( '<5g', '5g-10g', '10g-20g' );
    $output = '';
    for( $i=0; $i<count($options); $i++ ) {
      $output .= '<option ' 
                 . ( $_GET['sel'] == $options[$i] ? 'selected="selected"' : '' ) . '>' 
                 . $options[$i] 
                 . '</option>';
    }