Basically what I'm trying to do is update the value attribute of the hidden input field contained in the selected item when the selectable () user interface stops working.
If an element is selected, then the input value must be an attribute of the name of this particular LI, whereas if the element is not selected, the value must be updated as empty.
HTML example:
<ul id="selector">
<li class="networkicon shr-digg" name="shr-digg">
<div></div>
<label>Digg</label>
<input type="hidden" value="" name="bookmark[]" />
</li>
<li class="networkicon shr-reddit" name="shr-reddit">
<div></div>
<label>Reddit</label>
<input type="hidden" value="" name="bookmark[]" />
</li>
<li class="networkicon shr-newsvine" name="shr-newsvine">
<div></div>
<label>Newsvine</label>
<input type="hidden" value="" name="bookmark[]" />
</li>
</ul>
Script Example:
$(function() {
$("#selector").selectable({
filter: 'li',
selected: function(event, ui) {
$(".ui-selected").each(function() {
$(this).children('input').val($(this).attr('name'));
});
},
unselected: function(event, ui) {
$(".ui-selected").each(function() {
$(this).children('input').val('');
});
}
});
});
source
share