带有2个变量的If语句?

时间:2015-01-27 11:01:36

标签: javascript

我试图调整这个测量和计算地毯的形式,表格只允许你选择宽度4米或5米,你想要的长度和价格范围,但继承人我的问题,我试图让它成为一个如果宽度为5米且价格范围超过9.99

,则会弹出警告框
function validateForm() {
  var x = document.forms["quickestimate"]["width"].value;
  var p = document.forms["quickestimate"]["pricerange"].value;
  if (x == null || x == "5") {
     // your allowed 5m wide just under 9.99
     return true;
  } else if (p == null || p >= "9.99"){
     alert("Can't have 5m Wide and over £9.99");
     return false;
  }
}

我出错的任何想法?

1 个答案:

答案 0 :(得分:0)

function validateForm() {
  var x = document.forms["quickestimate"]["width"].value;
  var p = document.forms["quickestimate"]["pricerange"].value;
  if ((x == "5") && (p >= "9.99")) {
     // your allowed 5m wide just under 9.99
     return true;
  } else {
     alert("Can't have 5m Wide and over £9.99");
     return false;
  }
}