6👍
✅
First you are missing a '
in $('#search)
,
Second you need to use .val()
if you wish to get the value from the input.
$(document).ready( function(){
$('#search').keyup(function() {
$.ajax({
type: "POST",
url: "http://localhost:8000/overview",
data: {
'search_text': $('#search input[name=vehicle]').val()
},
success: searchSuccess,
dataType: 'html'
});
});
});
Demo
$(document).ready( function(){
$('#search').keyup(function() {
console.log($('#search input[name=vehicle]').val())
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="search">
<input type="text" name="vehicle">
</div>
- [Django]-Filter/order django rest api on a property=value but property is a value instead of a field
0👍
Or you can use oninput event like this
document.querySelector('input[name=vehicle]').oninput=function(){
alert(this.value)
};
OR
$('input[name=vehicle]').oninput(function(){
alert(this.value)
});
- [Django]-Non_field_errors : ["Expected a list of items but got type "dict"."]
- [Django]-How to filter Django annotations on reverse foreign key fields
- [Django]-How to set a field of the model in view using generic views?
- [Django]-Django List objects that will be deleted by deleting the current object
Source:stackexchange.com