如何修复单选按钮默认与两个单选按钮不同的字段

时间:2017-09-28 09:36:44

标签: javascript python web

我在网站上有两个单选按钮不同的字段名称。第一个radiobutton delivery_option(我自己制作),第二个单选按钮(carrier_id)。我想要两个单选按钮之间的关系。如果我检查delivery_option自动检查单选按钮carrier_id。如何解决?

    <template id="delivery_opt" inherit_id="website_sale.payment" customize_show="True" name="Delivery Option">

        <xpath expr="//div[@id='payment_method']" position="before">

            <div class="row" id="delivery_option">
              <div class="col-lg-5 col-sm-6">
              <h4>Choose your Delivery</h4>
                  <ul class="list-unstyled">
                      <li>
                          <label>
                              <input value="once" type="radio" name="delivery_options"
                                t-att-checked="order.delivery_options == 'once' and 'checked' or False"
                                />
                              <span>Every day</span>
                          </label>
                      </li>
                      <li>
                          <label>
                              <input value="twice"  type="radio" name="delivery_options"
                                t-att-checked="order.delivery_options == 'twice' and 'checked' or False"
                                  />
                              <span>Every two day</span>
                          </label>
                      </li>
                  </ul>
              </div>
          </div>

  </xpath>

</template>

<template id="delivery_method_def" name="Delivery Method Default" inherit_id="website_sale.payment">
    <xpath expr="//div[@id='payment_method']" position="before">
        <div t-if="deliveries" class="row" id="delivery_carrier">
            <div class="col-lg-5 col-sm-6">
            <h4>Choose your Delivery Method</h4>
                <ul class="list-unstyled">
                    <li t-foreach="deliveries" t-as="delivery">
                        <t t-if="delivery.available">
                            <label>
                                <input t-att-value="delivery.id" type="radio" name="delivery_type"
                                    t-att-checked="order.carrier_id and order.carrier_id.id == delivery.id and 'checked' or False"/>
                                <abbr t-att-title="delivery.website_description"><span t-field="delivery.name"/></abbr>
                                <span class="badge" t-field="delivery.price"
                                    t-options='{
                                        "widget": "monetary",
                                        "from_currency": delivery.product_id.company_id.currency_id,
                                        "display_currency": website_sale_order.currency_id
                                    }'/>
                                <div t-field="delivery.website_description" class="text-muted"/>
                            </label>
                        </t>
                    </li>
                </ul>
            </div>
        </div>
    </xpath>
</template>

1 个答案:

答案 0 :(得分:0)

尝试以下代码。更改delivery_options字段时使用javaScript事件函数,如果delivery_options值为true,则其他字段也将更改。并且还为carrier_id提供id。

<?php
include("page.html");
include("databaseConnection.php");

$sth = $conn->prepare("SELECT ID, userName from passwords");
$sth->execute();

$result[] = $sth->fetchAll();

if(isset($_POST["showData"])){

echo "<table style='border: 2px solid black'>
<tr>
<th style='border: 1px solid red'>ID</th>
<th style='border: 1px solid black'>User Name</th>
</tr> <tbody>";
foreach ($result as $key => $value) {
    foreach ($value as $key1 => $value1) {
?>
<tr>
<td><? echo $value1['ID']; ?></td>
<td><? echo $value1['userName']; ?></td>
</tr>
<?php
    }

}
echo "</tbody></table>";
}
?>