<form>
<div class="content-search-block">
<div class="search-bar">
<div class="search-bar">
<input type="text" class="form-control" id="dname" name="dname" value="" placeholder="Otsi töötajaid">
<button type="submit" id="submit" class="icon"><i class="fa fa-search"></i></button>
</div>
</div>
</div>
</form>
So i have this kind of search field. This kind of start on JavaScript file.(yeah in WP) But seems that my script doesn't load on submit button?
jQuery(document).ready(function(){
jQuery('#submit').click(function(){
var name = jQuery("#dname").val();
});
});
I tried even
jQuery(document).ready(function(){
jQuery('#submit').click(function(){
var name = jQuery("#dname").val();
jQuery.ajax({
url: '/wp-admin/admin-ajax.php',
type: 'POST', // Adding Post method
dataType: 'JSON',// Including ajax file
data: {'action': 'do_search', 'dname':name}, // Sending data dname to post_word_count function.
success: function(data){ // Show returned data using the function.
alert(data);
}
});
});
});
Why? script is enqueued and loaded at the loading on page. Still nada.