i want to synchronise a simple html list, like the one below with a drop down list in a form
<div id="navcontainer">
<ul id="navlist">
<li id="active"><a href="#" id="current">Item one</a></li>
<li><a href="#">Item two</a></li>
<li><a href="#">Item three</a></li>
<li><a href="#">Item four</a></li>
<li><a href="#">Item five</a></li>
</ul>
</div>
#navlist li
{
display: inline;
list-style-type: none;
padding-right: 20px;
}
meaning that, for any selected element from the list, using a javascript, i want to be able on one side to memorise the selected item, and on the other part to update the elements in a drop down list. is it possbile?
thank you!
edit:
having this code, i want to display for each product the maximum value of his stock in the select list, when the product is selected
<script>
$(function ()
{
var $select = $('#mySelect');
$('#navlist li a').live('click', function ()
{
$select.val($(this).text());
});
});
</script>
<form name="add-to-basket" method="post" action="<?= Route::url('Add to Basket', array('sale_id' => $sale->id)); ?>">
<? foreach ($types as $type):?>
<div id="navcontainer">
<ul id="navlist">
<li value = "<?=$type->stock_2 ?>"><a href="#"><?= $type->label;?><?= $type->stock_2;?></a></li>
</ul>
</div>
<? endforeach; ?>
<select name="number" id="mySelect">
<? for ($i = 1; $i <= $type->stock_2; $i++): ?>
<option <?= $type->stock_2 == $i ? 'selected="selected"' :''?> value="<?= $i ?>"><?= $i ?></option>
<? endfor; ?>
</select>
</form>
http://jsfiddle.net/stofke/gukh2
I hope it’s not this what you want because if someone else buys an item while another person is doing the same, the javascript will not have the accurate count of items. This does not seem to me a javascript only job.
HTML
CSS
JavaScript