0
I have a following code:
INPUT
<div class="row">
<div class="form-group">
<div class="col-sm-3">
<div class="form-group input-group">
<input id="contact-input" type="text" id="search" class="form-control input-search-doc" placeholder="Documento" required>
<span class="input-group-btn">
<button class="btn btn-default btn-search-doc" type="button">
<i class="fa fa-search"></i>
</button>
</span>
</div>
</div><!-- <div class="col-sm-3"> -->
</div><!-- <div class="form-group"> -->
</div><!-- <div class="row"> -->
AJAX
$(".btn-search-doc").on("click",function(){
var title = $(this).find('input.input-search-doc').val();
alert(title);
$("#result").html("<img src='ajax-loader.gif'/>");
$.ajax({
type:"post",
url:"../connect/post/select.php",
data:"title="+title,
success:function(data){
$("#result").html(data);
$("#search").val("");
}
});
});
It should take the text inside the input and send via Ajax to my select, but it can’t get the text inside the input "input-search-doc", always returns to me in var_dump : string 'Undefined' (length=9)
Someone has an idea why he’s not getting any value?
Your selector should look like this: var title = $('.input-search-doc'). val(); it makes no sense to use this in this case, only if it were a form, and you were to give a Ubmit
– Gabriel Rodrigues
Thank you was right.
– Wagner Viana