javascript - Jsp Alert If else statement -
for following want run script see if string equal when button clicked.
<wts:input label="chemical name todo" inputid="synname" path="chemicalname" maxlength="100" size="100"></wts:input> <div class="form-group"> <div class="col-md-offset-2 col-md-2"> <input type="submit" value="search" id="searchbutton" class="btn btn-primary" onclick="unknownalert()" /> <c:if test="${techview}"> <input type="hidden" name="techview" value="${techview}"> </c:if> <input type="reset" value="reset" id="resetbutton" class="btn btn-default"/> </div> </div> <script> function unknownalert() { if($('#synname') == 'unknown'){ alert("unknown working"); } } </script>
when user types in string, unknown or unknown, once search button clicked runs script know if alert. stuck on how check condition.
should be:
if($('#synname').val() === 'unknown')
you want compare against value of input, not input (that's jquery dom object).
additionally if want case insensitive can use tolower()
function before compare:
if($('#synname').val().tolower() === 'unknown')
Comments
Post a Comment