2012-02-20 4 views
-1

У меня есть таблица с 8 кнопками ввода радио, и я хочу обновить общую цену в зависимости от выбора радиоввода пользователя. Как это сделать с помощью jQuery?Обновить итоговую цену на основе выбора радиоввода

<table> 
    <tr> 
    <td></td> 
    <form name="m" action="" method="post"> 
     <th> <input id="test" name="purchaseChoice" class="radio" onclick="togglePrices(false);" type="radio" value="P2"/> 
     <label for="purchaseChoice">£5</span> </label> 
     <input id="test" name="purchaseChoice" class="radio" onclick="togglePrices(true);" type="radio" value="P1"/> 
     <label for="purchaseChoice">£10</label> 
     </th> 
     <th class=""> <input id="test" name="purchaseChoice" class="radio" onclick="togglePrices(true);" type="radio" value="S111"/> 
     <label for="purchaseChoice">£20</label> 
     <input id="test" name="purchaseChoice" class="radio" onclick="togglePrices(false);" type="radio" value="S112"/> 
     <label for="purchaseChoice">£30</label> 
     </th> 
     <th class=""> <input id="test" name="purchaseChoice" class="radio" onclick="togglePrices(true);" type="radio" value="S131"/> 
     <label for="purchaseChoice">£40</label> 
     <input id="test" name="purchaseChoice" class="radio" onclick="togglePrices(false);" type="radio" value="S132"/> 
     <label for="purchaseChoice">£50</label> 
     </th> 
     <th class="highlight"> <input id="test" name="purchaseChoice" class="radio" onclick="togglePrices(true);" type="radio" value="S121"/> 
     <label for="purchaseChoice">£60</label> 
     <input id="test" name="purchaseChoice" class="radio" onclick="togglePrices(false);" type="radio" value="S122"/> 
     <label for="purchaseChoice">£70</label> 
     </th> 
    </form> 
    </tr> 
    <tr> 
    <th class="total">TOTAL YOU PAY</th> 
    <th> 
    <div class="Priceband"></div> 
    </th> 
    </tr> 
</table> 

Благодаря

+0

Где ваши цены? –

+0

Значения цен присутствуют во вводе, поданном в конце. В принципе, как вы можете видеть, у меня есть 8 значений: P1, P2, S112, S111, S121, S122, S131 и S132 – gek

ответ

0

Если я правильно понимаю ваши требования, вы просто хотите обновить цену с измененным выбором.

, пожалуйста, найдите нижеприведенный код. может быть полезно для вас.

<table> 
    <tr> 
    <td></td> 
    <form name="m" action="" method="post"> 
     <th> <input id="test" name="purchaseChoice" class="radio" onclick="togglePrices(this);" type="radio" value="P2"/> 
     <label for="purchaseChoice">£5</span> </label> 
     <input id="test" name="purchaseChoice" class="radio" onclick="togglePrices(this);" type="radio" value="P1"/> 
     <label for="purchaseChoice">£10</label> 
     </th> 
     <th class=""> <input id="test" name="purchaseChoice" class="radio" onclick="togglePrices(this);" type="radio" value="S111"/> 
     <label for="purchaseChoice">£20</label> 
     <input id="test" name="purchaseChoice" class="radio" onclick="togglePrices(this);" type="radio" value="S112"/> 
     <label for="purchaseChoice">£30</label> 
     </th> 
     <th class=""> <input id="test" name="purchaseChoice" class="radio" onclick="togglePrices(this);" type="radio" value="S131"/> 
     <label for="purchaseChoice">£40</label> 
     <input id="test" name="purchaseChoice" class="radio" onclick="togglePrices(this);" type="radio" value="S132"/> 
     <label for="purchaseChoice">£50</label> 
     </th> 
     <th class="highlight"> <input id="test" name="purchaseChoice" class="radio" onclick="return togglePrices(this);" type="radio" value="S121"/> 
     <label for="purchaseChoice">£60</label> 
     <input id="test" name="purchaseChoice" class="radio" onclick="togglePrices(this);" type="radio" value="S122"/> 
     <label for="purchaseChoice">£70</label> 
     </th> 
    </form> 
    </tr> 
    <tr> 
    <th class="total">TOTAL YOU PAY</th> 
    <th> 
    <div class="Priceband"></div> 
    </th> 
    </tr> 
</table> 
<script language="javascript" type="text/javascript" > 

    function togglePrices(e) { 
     var price = $(e).val(); 
     $(".Priceband").html(price); 
    } 

</script> 
+0

Я пробовал это, но я не могу получить какую-либо цену в моем «Прайсбанде» div – gek

+0

Я пробовал тот же код на моем конце. Его работа прекрасна для меня. Может быть, вам не хватает ссылок на JQuery. Убедитесь, что у вас есть ссылка на библиотеку jquery. –

+0

У меня есть определенные ссылки jQuery, поскольку другой код jquery на странице отлично работает. Я обновил код выше, чтобы вы снова просмотрели, пожалуйста. Я обнаружил некоторые ошибки из того, что я впервые вложил, может быть, поэтому не работает? Большое спасибо за вашу помощь – gek

Смежные вопросы