Javascript 表单提交时未选中所需的复选框
我已经用我的bigcartel onlineshop模板闲逛了将近一周,继续编辑一个已经存在的主题,以符合我的想象 为了符合我国有关在线销售的法律要求,我需要添加一个复选框,表明我的客户已经阅读、理解并接受了我的店铺条件条款——总之——没有人阅读的部分:D 首先,我尝试在部分中插入一个带有文本的复选框,然后Javascript 表单提交时未选中所需的复选框,javascript,forms,validation,checkbox,required,Javascript,Forms,Validation,Checkbox,Required,我已经用我的bigcartel onlineshop模板闲逛了将近一周,继续编辑一个已经存在的主题,以符合我的想象 为了符合我国有关在线销售的法律要求,我需要添加一个复选框,表明我的客户已经阅读、理解并接受了我的店铺条件条款——总之——没有人阅读的部分:D 首先,我尝试在部分中插入一个带有文本的复选框,然后 <input id="agb_check" name="agb_check" type="checkbox" required /><span id="agb_txt"&g
<input id="agb_check" name="agb_check" type="checkbox" required /><span id="agb_txt">SOME TEXT.</span>
好吧,那也不行
你们有什么建议吗
网站是:explore.dlld-fashion.de
基本上,当你试图重新计算你的运输成本时,弹出的“需要复选框”是完美的
感谢您的时间和来自德国的问候
丹尼斯
HTML表单代码:
<form id="cart-form" {% unless cart.shipping.enabled or cart.discount.enabled %}class="no_options"{% endunless %} method="post" action="/cart">
<div id="cart_description">
<section id="cart_items">
<ul>
{% for item in cart.items %}
<li class="cart_item {% unless item.product.has_default_option %}with_option{% endunless %}" id="item-{{ item.id }}">
<div class="item_image"><img src="{{ item.product.image | product_image_url size:"thumb" }}" alt="Photo of {{ item.name }}"></div>
<dl>
<dt><a href="{{ item.product.url }}">{{ item.product.name }}</a></dt>
<dd class="item_price">{{ item.unit_price | money_with_sign }}{% if item.quantity > 1 %}<span class="item_quantity">(x{{ item.quantity }})</span>{% endif %}</dd>
<dd class="quantity_input" style="display:none">{{ item | item_quantity_input }}</dd>
{% unless item.product.has_default_option %}<dd class="item_option">{{ item.option.name }}</dd>{% endunless %}
</dl>
<a href="#" class="remove_item" title="Remove item from cart">Remove item</a>
</li>
{% endfor %}
</ul>
</section>
{% if cart.shipping.enabled or cart.discount.enabled %}
<section id="cart_options">
<ul>
{% if cart.shipping.enabled %}
{% if cart.shipping.strict %}
<li id="shipping_option">
<label for="country">Shipping</label>
{{ store.country | country_select }}
{% if cart.shipping.pending %}
{% if cart.country %}
<span class="no_shipping">We don't ship to {{ cart.country.name }}</span>
{% endif %}
{% endif %}
</li>
{% endif %}
{% endif %}
{% if cart.discount.enabled %}
<li id="cart_discount" class="cart_item">
{% if cart.discount.pending %}
<label id="cart_discount_label" for="cart_discount_code">Discount</label>
{{ cart.discount | discount_code_input }}
{% elsif cart.discount.free_shipping %}
<label for="cart_discount_code">Discount</label>
<p>{{ cart.discount.name }}</p>
{% else %}
<label for="cart_discount_code">Discount</label>
<p>{{ cart.discount.name }}</p>
{% endif %}
</li>
{% endif %}
</ul>
<div class="cart-update">
<button id="update-btn-footer" class="update-btn button disabled" name="update" type="submit" title="Update your cart total"><span>Update total</span></button>
</div>
</section>
{% endif %}
</div>
<section id="cart_summary">
<ul>
<li>
<h3>Items</h3>
<span>{{ cart.subtotal | money_with_sign }}</span>
</li>
{% if cart.shipping.enabled %}
<li id="cart-shipping-tax">
<h3>Shipping</h3>
{% if cart.shipping.pending %}
{% if cart.country %}
<span class="shipping-amount">Select another country</span>
{% else %}
<span class="shipping-amount">Select country</span>
{% endif %}
{% else %}
<span class="shipping-amount">{{ cart.shipping.amount | money_with_sign }}</span>
{% endif %}
</li>
{% else %}
<li id="cart-shipping-tax" class="not_set">
<h3>Shipping</h3>
<span>Applicable fees apply</span>
</li>
{% endif %}
{% if cart.discount.enabled %}
{% if cart.discount.pending %}
{% elsif cart.discount.free_shipping %}
<li>
<h3>Discount</h3>
<span>Free shipping!</span>
</li>
{% else %}
<li>
<h3>Discount</h3>
<span>-{{ cart.discount.amount | money_with_sign }}</span>
</li>
{% endif %}
{% endif %}
<li id="cart_total">
<h3>Total</h3>
<h2>{{ cart.total | money_with_sign }}</h2>
</li>
</ul>
<button id="checkout-btn" class="button" onclick="validiere()" title="Checkout" type="button">Checkout</button>
<input id="agb_check" name="agb_check" type="checkbox" required /><span id="agb_txt">Hiermit erkläre ich mich mit den geltenden AGB's einverstanden.</span>
</section>
</form>
{cart.items%中的项目为%s}
-
{{item.unit|price{money|u with_sign}{%if item.quantity>1%}(x{{item.quantity}}}{%endif%}
{{项目|项目_数量_输入}
{%inspect item.product.has_default_option%}{{item.option.name}{%endinspect%}
{%endfor%}
{%if cart.shipping.enabled或cart.discount.enabled%}
{%if cart.shipping.enabled%}
{%if cart.shipping.strict%}
-
航运
{{store.country | country_select}
{%if cart.shipping.pending%}
{%if cart.country%}
我们不发送到{{cart.country.name}
{%endif%}
{%endif%}
{%endif%}
{%endif%}
{%if cart.discount.enabled%}
-
{%if cart.discount.pending%}
优惠
{{cart.discount | discount_code_input}
{%elsif cart.discount.free_shipping%}
优惠
{{cart.discount.name}}
{%else%}
优惠
{{cart.discount.name}
{%endif%}
{%endif%}
更新总数
{%endif%}
-
项目
{{cart.subtotal}货币}
{%if cart.shipping.enabled%}
-
航运
{%if cart.shipping.pending%}
{%if cart.country%}
选择其他国家/地区
{%else%}
选择国家
{%endif%}
{%else%}
{{cart.shipping.amount}货币{u符号}
{%endif%}
{%else%}
-
航运
适用费用适用
{%endif%}
{%if cart.discount.enabled%}
{%if cart.discount.pending%}
{%elsif cart.discount.free_shipping%}
-
优惠
免费送货!
{%else%}
-
优惠
-{{cart.discount.amount}货币{u符号}
{%endif%}
{%endif%}
-
全部的
{{cart.total}货币{u符号}
结账
我在geltenden AGB的投资站。
可以从表单的提交按钮调用验证功能。如果验证失败,它应该返回false
如果您将函数更改为以下内容,它应该可以工作:
function validiere(){
if(document.getElementById("agb_check").checked){
document.getElementById("cart-form").submit();
}
else {
document.getElementById("agb_text").style.color="red";
}
return false;
}
写
防止默认行为(提交)
还有,只是
document.getElementById('theFormId').onsubmit = function() {
if(!validate())
return false;
}
else{
return true;
}
}
应该能用。我想不是
window.stop()
您应该返回false代码>您在服务器上使用什么类型的语言?您永远不应该在客户端进行验证,因为用户只需更改您的JavaScript即可。您应该将数据发送到服务器端逻辑,并在那里进行检查。如果已选中,则应使用布尔值,如果选中,则继续正常导航如果未选中,则向用户发送一条消息,如果用户未选中该框并停止订单完成,则他将无法继续。您可以提供整个表单HTML吗?因此,使用JS的整个解决方案似乎不起作用。单击submit按钮,似乎会触发另一个功能,将您引导到签出站点。但是,如何修复提交按钮和复选框中所需属性之间的连接呢?该复选框当前会触发运费“刷新”按钮。我在原始帖子中发布了代码!好的,我刚刚添加了一个非JQuery解决方案不幸的是,它不起作用。它仍然提交表格(表单是否具有id?如果函数validate()正确,则返回true;如果函数不正确,则返回false?validate()函数)函数确实起作用。唯一不起作用的是停止加载过程,而加载过程也不起作用。该按钮仍然会触发指向另一端的链接。它在这里起作用。如果从表单/脚本中发布更多代码,我们可能会进一步调试它。我刚刚发布表单的html部分作为编辑。不幸的是,bigcartel dOESN不允许编辑原始javascript,它会触发一个不会被prevent.default代码停止的函数。我网站的url是:explore.dlld-fashion.de
function validiere(){
if(document.getElementById("agb_check").checked){
document.getElementById("cart-form").submit();
}
else {
document.getElementById("agb_text").style.color="red";
}
return false;
}
$("#checkout-btn").click(function(event)
{
event.preventDefault();
});
document.getElementById('theFormId').onsubmit = function() {
if(!validate())
return false;
}
else{
return true;
}
}