Reputation: 93
Ive read through a bunch of similar issues with autocomplete but none of the solutions presented have helped me with this. I have a form that is searching for usernames in a database. The autocomplete list is populating with the appropriate names, and from the looks of the code being returned for the autocomplete, the names are coming back with the appropriate IDs and VALUEs.
Why am I unable to submit the form with any data being passed along?
The screen is refreshing as if the form was submitted but no information comes back with the GET. Just a "?" at the end of the url. If I use the keyboard or use the mouse to select an option in the autocomplete dropdown, no information is passed with the GET. Even if I type in something and use a submit button and disregard the autocomplete dropdown there is still no information being passed along.
Here is the current HTML.
<title>TEST</title>
<link href="jquery-ui.min.css" rel="stylesheet" />
<link href="autocomplete.css" rel="stylesheet" />
<script src="jquery-1.11.2.js"></script>
<script src="jquery-ui.min.js"></script>
<script src="jquery.ui.autocomplete.html.js"></script>
<script type="text/javascript" src="../test.php"></script>
</head>
<body>
<form id="searchform" method="GET">
<input type="text" id="searchterm" placeholder="Search For Client">
<input type="submit" value="Submit">
<script type="text/javascript" src="../js/watchdog.js"></script>
</form>
</body>
</html>
and the JS named "watchdog" that is watching that form field. What am I missing?
$(function() {
$("#topic_title").autocomplete({
source: "ajax.php",
minLength: 2,
select: function(event, ui) {
var item = ui.item;
console.log(item,ui);
if(item) {
$(this).val(item.value);
$(this.form).submit();
return false;
}
}
});
});
I should also add, this is the seventh or either variation of this script with the same empty results.
Thanks in advance for any help with this.
Upvotes: 2
Views: 2546
Reputation: 7483
the autocomplete code looks fine for me. the only problem I can see in your code is you didn't provide the name
attribute in the <input>
so your browser didn't append it to the url.just replace this
<input type="text" id="searchterm" placeholder="Search For Client">
with this
<input type="text" id="searchterm" name="clientId" placeholder="Search For Client">
(remember to change clientId
to the name that your server expects)
Upvotes: 2