问题
I have a Jquery Autocomplete
. Its working fine. Values are selected when i move up and down from keyboard arrow key or hover a mouse on a particular value. But when i press button to put my selected value inside text box it doesn't work, instead if i press enter on keyboard the value is inputted in text box.
Let me give me my code
for auto complete ::
$(document).ready(function hello(){
var myVar2 = <%=request.getAttribute("variable1")%>
$("input#assignedtoid").autocomplete({
source: myVar2
});
});
<input dojoType="dijit.form.ValidationTextBox" id="assignedtoid" name="assignedtoname" required="true" onfocus="hello()" value=<%=session.getAttribute("Username")%> onblur="valassignedtoid()">
In above code myVar2
is my data in Json
form that is assigned a source for autocomplete. Values coming fine in autocomplete. OnFocus
event in input tag
i call hello()
function. Why it is that value is not getting selected on mouse button click
. However the site from where i picked up the code. the value is getting selected on Mouse click as well as on enter pressing. The site
is ::
http://jqueryui.com/demos/autocomplete/
Here the only diff is that there Source is static i am getting it from database in the form of Json
thru myVar2
. I am using IE. Using dijit.form.ValidationTextBox
as my input
Please help. Thanks ..
The Edited Part ::
i have Imported The following js files::
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js"></script>
<script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/autocomplete/jquery.autocomplete.js"></script>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
And when i run it in Google chrome
i don't get any auto complete. I do get an error
that ::
<script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/autocomplete/jquery.autocomplete.js"></script>
is not found. And indeed its not valid anymore. But my auto complete works great when i run it on IE. Can this be the reason ? Also can u tell me which Jquery imports from the above i should delete if any of them is extra. Kinda confused.
i have taken the code from here ::
http://jqueryui.com/demos/autocomplete/
Thanks again.
回答1:
Remove onfocus="hello()"
from your markup, and fix javascript:
dojo.require("dijit.form.ValidationTextBox");
dojo.ready(function () {
var myVar2 = <%=request.getAttribute("variable1")%>;
$("input#assignedtoid").autocomplete({
source: myVar2
});
});
BTW, Why don't you want to use dijit.form.ComboBox
for pure dojo solution?
UPDATE
If you want to use google cdn, you need these imports:
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.19/themes/base/jquery-ui.css" type="text/css" media="all" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.19/jquery-ui.min.js" type="text/javascript"></script>
来源:https://stackoverflow.com/questions/10512648/value-not-getting-selected-from-an-autocomplete-on-mouse-button-click