Добрый день!
Как нижеприведенный код для radiobuttons изменить под select. Спасибо!
Исходные строки кода с радиокнопками:
<span id="sub_price" style="display: none;">{$cart->total_price}</span>
<span id="subtotal_price"></span> {$currency->sign}
... радиокнопки:
<input type="radio" name="delivery_id"onclick="select_delivery_method({$delivery->id});" value="{$delivery->id}" {if $delivery_id==$delivery->id}checked{elseif $delivery@first}checked{/if} id="deliveries_{$delivery->id}">
<label for="deliveries_{$delivery->id}">{$delivery->name} <span id="delivery_price_{$delivery->id}">{$delivery->price}</span> {$currency->sign}</label>
<script>
function select_delivery_method(method_id)
{
radiobuttons = document.getElementsByName('delivery_id');
for(var i=0;i<radiobuttons.length;i++)
{
if(radiobuttons[i].value == method_id)
{
radiobuttons[i].checked = 1;
}
}
var subtotal = parseFloat(document.getElementById('sub_price').innerHTML);
var delivery = 0;
if(document.getElementById('delivery_price_'+method_id))
delivery = parseFloat(document.getElementById('delivery_price_'+method_id).innerHTML);
total = subtotal+delivery;
document.getElementById('subtotal_price').innerHTML = total;
}
</script>
<script>
select_delivery_method(1);
</script>
Код select.
<select name="delivery_id" onclick="select_delivery_method({$delivery->id});">
<option value="{$delivery->id}">{$delivery->name}
<span id="delivery_price_{$delivery->id}">{$delivery->price}</span> {$currency->sign}
</option>
</select>