禁用具有指定类的输入,onClick?

时间:2014-10-16 22:59:31

标签: javascript forms radio-button disabled-input

我有一个表格(见下面的图片链接),当一个" no"时,需要禁用一组隐藏的输入。单击单选按钮并在"是"单击单选按钮。有三个不同的类,每个类有四个隐藏的输入。另外,我需要在Javascript而不是Jquery中执行此操作,因为无论出于何种原因我的Jquery都没有正常工作(可能是因为插件中的wordpress头部内有多个声明)。 http://i59.tinypic.com/ofddk.jpg

这三个类是:

poolHeatingFee,petFee和propertyDamageProtection

...并且每个类都有相应的是和否单选按钮附加到单击事件,这些按钮设置和清除显示价格的div的内部HTML。 我想也许我可以修改这些函数来接收一个额外的参数,这将是输入的类名,并在相应的函数中启用/禁用输入......

            <script type="text/javascript">
            function clearFee(theNamedFee){
            document.getElementById(theNamedFee).innerHTML = '0.00';
            }

            function showFee(theNamedFee,someFee){
            document.getElementById(theNamedFee).innerHTML = someFee;
            }
            </script>

以下是无线电的代码......

            <tr class="cart_item">
                <td class="product-name">

                    Preheat Pool?&nbsp;&nbsp;<input type="radio" name="preheatPoolSelect" id="preheatPoolYes" value="yes" onclick='showFee("priceDisplayPoolHeating","8.00")' checked><label for="preheatPoolYes">Yes</label>&nbsp;&nbsp;<input type="radio" name="preheatPoolSelect" id="preheatPoolNo" value="no" onclick='clearFee("priceDisplayPoolHeating")'><label for="preheatPoolNo">No</label>
                </td>
                <td class="product-total">                          
                    $<div id="priceDisplayPoolHeating" class="priceDisplay">8.00</div>                          </td>
            </tr>

            <tr class="cart_item">
                <td class="product-name">

                    Have Pet(s)?&nbsp;&nbsp;<input type="radio" name="havePetsSelect" id="havePetsYes" value="yes" onclick='showFee("priceDisplayPetFee","7.00")' checked><label for="havePetsYes">Yes</label>&nbsp;&nbsp;<input type="radio" name="havePetsSelect" id="havePetsNo" value="no" onclick='clearFee("priceDisplayPetFee")'><label for="havePetsNo">No</label>
                </td>
                <td class="product-total">                          
                    $<div id="priceDisplayPetFee" class="priceDisplay">7.00</div>                           </td>
            </tr>

            <tr class="cart_item">
                <td class="product-name">

                    Property Damage Protection?&nbsp;&nbsp;<input type="radio" name="propertyDamageProtectionSelect" id="propertyDamageProtectionYes" value="yes" onclick='showFee("priceDisplayPropertyDamageProtection","4.00")' checked><label for="propertyDamageProtectionYes">Yes</label>&nbsp;&nbsp;<input type="radio" name="propertyDamageProtectionSelect" id="propertyDamageProtectionNo" value="no" onclick='clearFee("priceDisplayPropertyDamageProtection")'><label for="propertyDamageProtectionNo">No</label>
                </td>
                <td class="product-total">                          
                    $<div id="priceDisplayPropertyDamageProtection" class="priceDisplay">4.00</div>                         </td>
            </tr>

这是表格中的html ......

            <form id='paypalCheckout' action='https://www.paypal.com/cgi-bin/webscr' method='post' style="margin-bottom: 10px">

                <input type="hidden" name="item_name_1" value="Demo Vacation Home" />
                <input type="hidden" name="item_number_1" value="Demo-Vacation-Home" />
                <input type="hidden" name="amount_1" value="4" />
                <input type="hidden" name="quantity_1" value="1" />

                <input type="hidden" name="item_name_2" value="Refundable Damage Deposit" />
                <input type="hidden" name="item_number_2" value="Refundable-Damage-Deposit" />
                <input type="hidden" name="amount_2" value="3" />
                <input type="hidden" name="quantity_2" value="1" />

                <input type="hidden" name="item_name_3" value="Cleaning Fee" />
                <input type="hidden" name="item_number_3" value="Cleaning-Fee" />
                <input type="hidden" name="amount_3" value="2" />
                <input type="hidden" name="quantity_3" value="1" />

                <input type="hidden" name="item_name_4" value="12% Reservation Fee" />
                <input type="hidden" name="item_number_4" value="12%-Reservation-Fee" />
                <input type="hidden" name="amount_4" value="0.48" />
                <input type="hidden" name="quantity_4" value="1" />

                <input type="hidden" name="item_name_5" value="8% Tax Rate" />
                <input type="hidden" name="item_number_5" value="8%-Tax-Rate" />
                <input type="hidden" name="amount_5" value="0.32" />
                <input type="hidden" name="quantity_5" value="1" />

                <input type="hidden" name="item_name_6" value="Pool-heating Fee" class="poolHeatingFee"/>
                <input type="hidden" name="item_number_6" value="Pool-heating-Fee" class="poolHeatingFee"/>
                <input type="hidden" name="amount_6" value="8" class="poolHeatingFee"/>
                <input type="hidden" name="quantity_6" value="1" class="poolHeatingFee"/>

                <input type="hidden" name="item_name_7" value="Pet Fee" class="petFee"/>
                <input type="hidden" name="item_number_7" value="Pet-Fee" class="petFee"/>
                <input type="hidden" name="amount_7" value="7" class="petFee"/>
                <input type="hidden" name="quantity_7" value="1" class="petFee"/>

                <input type="hidden" name="item_name_8" value="Property Damage Protection" class="propertyDamageProtection"/>
                <input type="hidden" name="item_number_8" value="Property-Damage-Protection" class="propertyDamageProtection"/>
                <input type="hidden" name="amount_8" value="4" class="propertyDamageProtection"/>
                <input type="hidden" name="quantity_8" value="1" class="propertyDamageProtection"/>


                <input type='hidden' name='business' value='juliocpreciado@gmail.com' />
                <input type='hidden' name='shopping_url' value='http://www.dreamhomevacationrentals.com/cart/' />
                <input type='hidden' name='lc' value='en_US' />
                <input type='hidden' name='cmd' value='_cart' />
                <input type='hidden' name='charset' value='utf-8'>
                <input type='hidden' name='upload' value='1' />
                <input type='hidden' name='no_shipping' value='2' />
                <input type='hidden' name='currency_code' value='USD' id='currency_code' />
                <input type='hidden' name='custom' value='|||' />
                <input type='hidden' name='notify_url' value='http://www.dreamhomevacationrentals.com/store/ipn/'>
                <input type='hidden' name='return' value='http://www.dreamhomevacationrentals.com/thank-you/' />
                <input id='PayPalCheckoutButton' type='image' src='https://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif' value='Checkout With PayPal' />

            </form>

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

                <script type="text/javascript">
                function clearFee(theNamedFee,theNamedClass){
                document.getElementById(theNamedFee,theNamedClass).innerHTML = '0.00';

                    var elems = document.getElementsByClassName(theNamedClass);
                    for(var i = 0; i < elems.length; i++) {
                        elems[i].disabled = true;
                    }
                }

                function showFee(theNamedFee,someFee,theNamedClass){
                document.getElementById(theNamedFee).innerHTML = someFee;

                    var elems = document.getElementsByClassName(theNamedClass);
                    for(var i = 0; i < elems.length; i++) {
                        elems[i].disabled = false;
                    }

                }
                </script>