选择一个值时显示消息

时间:2015-07-01 16:10:26

标签: javascript parsley

不是一个复杂的,但我的编码知识非常有限。

我正在查找选择菜单中的值(小于$ 10,000)时要显示的消息,并且还会阻止表单提交。

<select name="levelofdebt" class="form-control" id="levelofdebt" required>
                                      <option value="" disabled selected="selected">Select total debt</option>
                                      <option value="$10,000 or less">Less than $10,000</option>
                                      <option value="$10-15k">$10,000 - $15,000</option>
                                      <option value="$15-20k">$15,000 - $20,000</option>
                                      <option value="$20-30k">$20,000 - $30,000</option>
                                      <option value="$30-40k">$30,000 - $40,000</option>
                                      <option value="$40-50k">$40,000 - $50,000</option>
                                      <option value="$50-60k">$50,000 - $60,000</option>
                                      <option value="$60-100k">$60,000 - $100,000</option>
                                      <option value="$100k +">$100,000 +</option>
                                    </select>

提前致谢

1 个答案:

答案 0 :(得分:0)

function selectchange(){
  if($("#levelofdebt").val() == '$10,000 or less')
    {
        
        alert('Amount Less than $10,000');
      return false; // prevents page reload
    }
  else{
     // Do something
  }

}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select name="levelofdebt" class="form-control" id="levelofdebt" required onchange="return selectchange();">
                                      <option value="" disabled selected="selected">Select total debt</option>
                                      <option value="$10,000 or less">Less than $10,000</option>
                                      <option value="$10-15k">$10,000 - $15,000</option>
                                      <option value="$15-20k">$15,000 - $20,000</option>
                                      <option value="$20-30k">$20,000 - $30,000</option>
                                      <option value="$30-40k">$30,000 - $40,000</option>
                                      <option value="$40-50k">$40,000 - $50,000</option>
                                      <option value="$50-60k">$50,000 - $60,000</option>
                                      <option value="$60-100k">$60,000 - $100,000</option>
                                      <option value="$100k +">$100,000 +</option>
                                    </select>