Problem
I'm trying to use two functions as conditions within an if else statement.
Then, upon either of them returning true, they carry out a desired process.
However, I can only get them to work independently, not as part of the if else statement.
What I've got
Currently, they work fine independently:
let input = document.querySelector('searchBox');
searchBox.addEventListener('keyup', (e) => {
if(e.keyCode === 13) {
alert(e.target.value);
return true;
}
})
$("#searchBtn").click(function(){
alert("Button clicked");
//alert("Button clicked");
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="search-bar" class="input-group custom-search">
<input id="searchBox" type="text" value="" class="form-control custom-search-input" placeholder="Search for product/material" >
<button id="searchBtn" class="btn btn-primary custom-search-botton" type="submit" >Search</button>
</div>
What's not working However, I'm trying to get them running as part of an if else statement. This is what I've got, but it's not turning over...
function enterPressed() {
$(document).on('keypress', function(e) { //enter button
if (e.which == 13) {
alert('You pressed enter!');
return true;
}
})
}
function buttonClicked() {
//a button (equivalent to buttonClicked)
$("#searchBtn").click(function() {
alert('You clicked the button!')
return true;
})
}
function start() {
if (enterPressed == true || buttonClicked == true) {
alert('You entered some information!!')
}
}
enterPressed();
buttonClicked();
start();
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="search-bar" class="input-group custom-search">
<input id="searchBox" type="text" value="" class="form-control custom-search-input" placeholder="Search for product/material">
<button id="searchBtn" class="btn btn-primary custom-search-botton" type="submit">Search</button>
</div>