I want to check if my textbox is empty using php, and if empty execute the code of ajax.
1st run of my code can detect my textbox ix empty but if I insert any text "means not empty" the ajax code does not execute. I don't know why. can someone help me to fix this bug. Thank you in advance.
PHP:
<input type="text" class="form-control" id="form3Name" name="Search" autocomplete="off" placeholder="Search..." required minlength="19">
<?php $str_text = $_GET['form3Name'];?>
<?php if (empty($str_text)):?>
<h6>search box empty</h6>
<?php elseif (!empty($str_text)):?>
<script type="text/javascript">
$(document).ready(function(){
$("#form3Name").keyup(function(){
var input = $(this).val();
if(input != "")
{
$.ajax({
url:"search",
method:"POST",
data:{input:input},
success:function(data){
$("#searchresult").html(data);
}
} )
}
else if(input == "")
{
header("refresh: 1;");
$("#searchresult").css("display","none");
}
});
});
</script>
<?php endif;?>
1st run of my code can detect my textbox ix empty but if I insert any text "means not empty" the ajax code does not execute. I don't know why. can someone help me to fix this bug. Thank you in advance.