When I click an item from a list, jQuery gets the class from the clicked element and writes it to the input field. Then the value from the input should be written to div # without any action.
HTML:
<ul>
<li class="NewYork">New York</li>
<li class="Paris">Paris</li>
<li class="Moscow">Moscow</li>
</ul>
<input type="text" id="city" value="" />
<div id="content"></div>
JQuery
$(document).ready(function() {
$('ul li').live('click', function() {
var select_value = $(this).attr('class');
$('input#city').val(select_value);
return false;
});
$('input#city').live('change', function() {
var content = $(this).val();
$('#content').text(content+' is beautiful city');
});
});
source
share