开发者

JavaScript - dropdown validation selection

I have 3 dropdowns, I would like to check in JavaScript that at least one selection has been ma开发者_如何转开发de, if not display a message. What would be the simplest way to do it in JavaScript?

id: dropdown1 id: dropdown2 id: dropdown3

Thanks


// need to make sure the first dropdown option is blank, then...

var dd1 = document.getElementById('dropdown1');
var dd2 = document.getElementById('dropdown2');
var dd3 = document.getElementById('dropdown3');

if (
  (dd1.selectedIndex == 0) && 
  (dd2.selectedIndex == 0) && 
  (dd3.selectedIndex == 0)
) {  
  alert('need to select at least one')
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜