I am checking whether an input field is empty or not, if it is empty display a button(google search) with a message if its has some value them display another button (update record) and a message.
My Elements:
- Input field
- button 1 ( field is empty ====> search)
- button 2 (field is not empty ====> update information)
Currently i can see the 2 buttons i created in the inspect element and it looks very bad.
I have replicated the code below, thanks!
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style>
/* #googlesearch{display:none;}
#updateinformation{display:none;}
#emptyform{display:none;} */
</style>
</head>
<body>
<div class="container">
<div class="form-group">
<label >Company name:</label>
<input onload="checker()" onkeydown="checker()" onchange="checker()" onkeyup="checker()" onfocus="checker()" class="form-control" id="txtcompany" value="dgfsd" >
<div id="txtinformator">
<small id="emptyform">Your form is empty, we recommend </small><br/>
<button id="googlesearch" class="btn btn-xs btn-primary">Search on Google</button>
<button id="updateinformation" class="btn btn-xs btn-success">Update Information</button>
</div>
</div>
</div>
<script>
$( document ).ready(function() {
$('#googlesearch').hide();
$('#updateinformation').hide();
$('#emptyform').hide();
});
// $( document ).ready(function() {
// if($('#txtcompany').val() == ""){
// $('#googlesearch').show();
// $('#emptyform').show();
// }
// else if (!$('#txtcompany').val()){
// $('#updateinformation').show();
// }
// else {
// $('#googlesearch').hide();
// $('#emptyform').hide();
// }
// });
function checker(){
if($('#txtcompany').val().length === 0){
$('#updateinformation').hide();
$('#googlesearch').show();
$('#emptyform').show();
}
else if (!$('#txtcompany').val()){
$('#updateinformation').hide();
}
else {
$('#emptyform').text('We suggest that you update this information.');
$('#updateinformation').show();
$('#googlesearch').hide();
}
}
</script>
</body>
</html>