Set value of input field to whatever is clicked
I have this feature where I want to have something that essentially functions the same as what's on http://www.iconfinder.com/
Notice how when you begin to enter something into the search bar, a list of suggestion appears. Whenever you click on one of them, the value of the changes to whatever is clicked on.
My approach to this problem is by using some jQuery code that is as follows:
$("h1#poli").click(function putIn_one(){
var htmlStr_one = $(this).html();
var seed_one_one = $('input#seed_one').val();
htmlStr_one = seed_one_one;
});
I already have code that correctly functions so that when someone enters something into the input field, a list of suggestions appears. will appear for every possible suggestion. What I need to do is find out how to make it so that when the is clicked on, the value of the input field is dynamically changed.
Any ideas?
Than开发者_运维问答ks,
Lance
You should do $('input#seed_one').val(htmlStr_one);
instead of htmlStr_one = seed_one_one;
. Also use live if you are dynamically fetching the results.
$("h1#poli").live('click', function putIn_one() {
var htmlStr_one = $(this).text();
$('input#seed_one').val(htmlStr_one);
});
精彩评论