如何根据其他字段更改文本字段

时间:2016-08-03 17:22:27

标签: javascript html

我想更改文本框值取决于其他字段,我做了但没有工作并且在" resoom"领域,



<script>
function resoome(){
	var get_balance=document.getElementById("Etisalat").value
	var alfees;
switch(get_balance){
		case get_balance>=0.5 && get_balance<=1:
	   alfees=0.10;
	   break;
	   case get_balance>1 && get_balance<=3:
	   alfees=0.15;
	   break;
	   case get_balance>3 && get_balance<=5:
	   alfees=0.25;
	   break;
	   case get_balance>5 && get_balance<=10:
	   alfees=0.50;
	   break;
	   case get_balance>10 && get_balance<=15:
	   alfees=0.60;
	   break;
	   case get_balance>15 && get_balance<=20:
	   alfees=0.70;
	   break;
	   case get_balance>20 && get_balance<=30:
	   alfees=0.80;
	   break;
	   case get_balance>30 && get_balance<=40:
	   alfees=0.90;
	   break;
	   case get_balance>40 && get_balance<=70:
	   alfees=1;
	   break;
	   case get_balance>70 && get_balance<=100:
	   alfees=1.25;
	   break;
	   case get_balance>100 && get_balance<=150:
	   alfees=1.50;
	   break;
	   case get_balance>150 && get_balance<=200:
	   alfees=2;
	   break;
	   case get_balance>200:
	   alfees=3;
	   break;
	    default:
        alfees=0;
		}
		resoom.value=alfees;
		}
</script>
&#13;
	<select name="Etisalat" id="Etisalat" onfocusout="resoome()" class="select Etisalat">
        <option value="0.5">0.5</option>
        <option value="1">1</option>
        <option value="1.5">1.5</option>
        <option value="3">3</option>
        <option value="4">4</option>
      </select>

<input type="number" id="resoom"style="width:90px"  name="resoom" placeholder="الرسوم"/>
&#13;
&#13;
&#13;

我如何解决它并根据其他场地改变房间值 感谢

1 个答案:

答案 0 :(得分:0)

 function resoome() {
    var x = document.getElementById("Etisalat").value;
    var get_balance = parseInt(x);
    var alfees;
    switch (true) {
        case get_balance > 0 && get_balance <= 1 : 
            alfees = 0.10;
            break;
        case get_balance > 1 && get_balance <= 3:
            alfees = 0.15;
            break;
        case get_balance > 3 && get_balance <= 5:
            alfees = 0.25;
            break;
        case get_balance > 5 && get_balance <= 10:
            alfees = 0.50;
            break;
        case get_balance > 10 && get_balance <= 15:
            alfees = 0.60;
            break;
        case get_balance > 15 && get_balance <= 20:
            alfees = 0.70;
            break;
        case get_balance > 20 && get_balance <= 30:
            alfees = 0.80;
            break;
        case get_balance > 30 && get_balance <= 40:
            alfees = 0.90;
            break;
        case get_balance > 40 && get_balance <= 70:
            alfees = 1;
            break;
        case get_balance > 70 && get_balance <= 100:
            alfees = 1.25;
            break;
        case get_balance > 100 && get_balance <= 150:
            alfees = 1.50;
            break;
        case get_balance > 150 && get_balance <= 200:
            alfees = 2;
            break;
        case get_balance > 200:
            alfees = 3;
            break;
        default:
            alfees = 0;
    }
    document.getElementById("resoom").value = alfees;
}

1.使用parseInt函数获取变量(get_balance)值作为数字。 2.如果您在case中使用的表达式返回true或false,请在switch case中使用true。