Я только что начал изучать HTML/CSS, javascript и jQuery на прошлой неделе и очень хотел бы помочь. Я создал форму с флажком (id #ship_to_billing), а затем поле fieldset (id #shipping_info), содержащее 5 текстовых полей. Используя JQuery, я настроил его так, чтобы, если флажок установлен, он переключает другие поля и скрывает их. Но я не могу понять, как дополнительно требовать того или другого, либо флажок должен быть проверен, либо все текстовые поля в наборе полей должны быть завершены. Мне не нужна тревога. Пожалуйста помоги!Обязательно установите флажок после флажка
Спасибо всем заранее, Сьюзен
<a type="button" class="btn btn-primary" href="#product-options" data-
toggle="modal">Buy This!</a>
<div class="modal hide fade" id="product-options">
<div class="modal-header center">
<a class="close" data-dismiss="modal">x</a>
<h3>When, Where and How?</h3>
</div>
<div class="modal-body l-m">
{% include 'datepicker' %}
<p>
<input type="hidden" name="properties[ship_to_billing]" value="" />
<label for="ship_to_billing" style="max-width:335px;">
<input id="ship_to_billing" type="checkbox" name="properties[Ship to Billing Address]" value="Yes" {% if properties.ship_to_billing %} checked="checked"{% endif %} />
<font size=1>Check here to have items shipped to your billing address (collected during checkout). Otherwise please fill out the information below.</font>
</label><br />
</p>
<div class="fieldgroup" id="shipping_info">
<label for="shipping_name">Name of Recipient:</label>
<input class="input-xlarge" type="text" id="shipping_name" placeholder="Name" name="properties[Recipient]" required="required" />
<p>
<label for="address_street">Shipping Address:</label>
<input class="input-xlarge" type="text" id="address_street" placeholder="Street Address" name="properties[Address]" required="required" />
<input class="input-xlarge" type="text" id="address_city" placeholder="City" name="properties[City]" required="required" />
<input class="input-medium" type="text" id="address_province" placeholder="State" name="properties[State]" required="required" />
<input class="input-medium" type="text" id="address_zip" placeholder="Zip Code" name="properties[Zip]" required="required" />
</p>
</div>
<p>
<label for="gift_msg">Gift Message :</label>
<textarea id="gift_msg" placeholder="Please type your message" name="properties[Gift Message]" rows="4" cols="45"></textarea>
</p>
</div>
<div class="modal-footer">
<div class="btn-group">
<button href="#" class="btn" data-dismiss="modal">Cancel</button>
<button type="submit" onclick="return validateShipping();" class="btn btn-primary" id="addtocart">Add To Cart</button>
</div>
</div>
</div>
Jquery:
<script>
$('#ship_to_billing').change(function(){
$('#shipping_info').toggle('show');
});
</script>
Я правильно понял, что если флажок установлен, поля исчезнут? Извините, если это немного педантично;) –
@ChrisKempen Я считаю, что флажок первоначально установлен. – silvenon
Я не уверен, понимаю ли я этот вопрос. Что вы подразумеваете под «дополнительным требованием»? Флажок должен быть проверен или поля должны быть заполнены почему? – silvenon