Javascript字段验证

时间:2012-12-14 20:47:43

标签: javascript forms

我有三个字段ForteID,disposition和Cancel_Disposition。现在我在我的javascript中有这个代码,它可以工作:

function validateForteID(){
  if(document.csform.ForteID.selectedIndex==0)
  {
    alert("Please select your Forte ID.");
    document.csform.ForteID.focus();
    return false;
  }
  if(document.csform.disposition.selectedIndex==0)
  {
    alert("Please select a disposition.");
    document.csform.disposition.focus();
    return false;
  }
  if(document.csform.Cancel_Disposition.selectedIndex==0)
  {
    alert("Please select a disposition.");
    document.csform.Cancel_Disposition.focus();
    return false;
  }
  return true;
}

我想要做什么并且不确定如何做,但如果字段处置是LOC或Backout,那么我希望它执行这部分代码:

if(document.csform.Cancel_Disposition.selectedIndex==0)
{
  alert("Please select a disposition.");
  document.csform.Cancel_Disposition.focus();
  return false;
}

但是只有处置是LOC或Backout。如果我需要更多解释,请告诉我,提前谢谢!

1 个答案:

答案 0 :(得分:0)

var cancel_disposition_value = document.csform.Cancel_Disposition[document.csform.Cancel_Disposition.selectedIndex].value;
if(cancel_disposition_value=='LOC' || cancel_disposition_value=='Backout')
{
    alert("Please select a disposition.");
    document.csform.Cancel_Disposition.focus();
    return false;
}