It's very straightforward to use jQuery to determine if a text input field is empty, e.g.:
<input type="text" name="is-exemption-1" value="">
var exemptnum = $(this).find("input[name^=is-exemption]");
if ($(exemptnum).val().length == 0) {
console.log('Success!');
}
But what if you need a user to select a value from a <ul>
dropdown menu and trigger something if that dropdown remains unselected? I've tried the following:
<div class="btn-group">
<a class="btn btn-default">Select ADC</a>
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
<span class="caret"></span>
</button>
<ul class="dropdown-menu" name="is-reviewer-1" role="menu" required="">
<li><a>Joe Reviewer, LANL</a></li>
<li><a>Jane Reviewer, LANL</a></li>
<li><a>Other</a></li>
</ul>
</div>
var reviewname = $(this).find("input[name^=is-reviewer]");
if (reviewname.selectedIndex == 0) {
console.log('yay!');
}
Also:
if ($(reviewname).val().length == 0) {
console.log('dude!');
}
Neither approach works. What's the correct one?
` dropdowns. You're generous if mistaken to assume I have not researched this matter -- I've indicated two examples I've tried based on that research.
– jimiayler Jan 29 '19 at 20:05