这是我的要求,如果文本框值不为null或者值大于0且下拉值为"选择"然后我想显示一个警报。我现在的问题是,无论条件是否为真,都不会触发警报。我在这做错了什么?有人可以帮忙吗
<script type="text/javascript">
function validate() {
var flag = true;
var gridView = document.getElementById('<%= myGridView.ClientID %>');
for (var i = 1; i < gridView.rows.length; i++) {
var dropdowns = gridView.rows[i].getElementsByTagName('Select');
var areas = gridView.rows[i].getElementsByTagName('textarea');
if (dropdowns != null && dropdowns.length > 1 && dropdowns[0] != null && areas != null && areas.length > 1 && areas[1] != null) {
if (areas[1].type == "textarea" && dropdowns[0].type == "select-one") {
var txtval = areas[1].value;
var ddlSelectedItem = dropdowns[0].value;
if (ddlSelectedItem == "Select" && (txtval != "" || txtval != null || txtval >0)) {
flag = false;
break;
}
else {
flag = true;
}
}
}
}
if (!flag) {
alert('Please make selection from the dropdown box. Thanks');
}
return flag;
}
</script>
答案 0 :(得分:0)
我通过将textarea更改为输入来解决我的问题
var areas = gridView.rows[i].getElementsByTagName('input');