「この住所に発送する」が選択されている場合にのみ検証するように、私書箱検証スクリプトを変更しようとしています。フォームは明らかに非常に簡単なフォーム検証を使用しています。フォーム セクションは次のとおりです。
<input type="radio" name="billing[use_for_shipping]" id="billing:use_for_shipping_yes" value="1" <?php if ($this->isUseBillingAddressForShipping()) {?> checked="checked"<?php }?> title="<?php echo $this->__('Ship to this address') ?>" onclick="$('shipping:same_as_billing').checked = true;" class="radio" /><label for="billing:use_for_shipping_yes"><?php echo $this->__('Ship to this address') ?></label></li>
<li class="control">
<input type="radio" name="billing[use_for_shipping]" id="billing:use_for_shipping_no" value="0" <?php if (!$this->isUseBillingAddressForShipping()) {?> checked="checked"<?php }?> title="<?php echo $this->__('Ship to different address') ?>" onclick="$('shipping:same_as_billing').checked = false;" class="radio" /><label for="billing:use_for_shipping_no"><?php echo $this->__('Ship to different address') ?></label>
これまでのところ、スクリプトは
Validation.add('validate-pobox', 'One or more items purchased cannot be shipped to a PO Box', function (v){
var pattern = /\b([P|p](OST|ost)?\.?\s?[O|o|0](ffice|FFICE)?\.?\s)?([B|b][O|o|0][X|x])\s(\d+)/;
if( document.getElementById("billing:use_for_shipping_yes").checked) // this isn't working
if (!pattern.test(v)) return true; else return false;
});
私は jQuery にあまり詳しくありません (ゆっくりと学んでいます!) が、どのボタンを選択しても、スクリプトはアドレス フィールドを検証します。私も試しました:
if( $("billing:use_for_shipping_yes").checked)
if( $("billing:use_for_shipping_yes").is("checked"))