最新消息:爱T-blog 最新域名 blog.itiwin.cn !!! php技术博客 magento博客

magento 出生日期下拉框 customer dob

magento 出生日期下拉框

dob

template/customer/widget  dob.phtml

<label for="<?php echo $this->getFieldId('month')?>"<?php if ($this->isRequired()) echo ' class="required"' ?>><?php if ($this->isRequired()) echo '<em>*</em>' ?><?php echo $this->__('Date of Birth') ?></label>
<div class="input-box customer-dob">
<?php
// days
echo "<select id=\"sDay\" name=\"sDay\" rel=\"".str_replace(":","\:",$this->getFieldId('day'))."\" class=\"dateselect\">";
$selected = (!$this->getDay()) ? "selected=\"selected\"" : "";
echo "<option value=\"\" ".$selected.">Day</option>";
for ($i = 1; $i <= 31; $i++) {
$ti = str_pad($i, 2, "0", STR_PAD_LEFT);
$selected = ($this->getDay() == $ti) ? "selected=\"selected\"" : "";
echo "<option value=\"".$ti."\" ".$selected.">".$i."</option>";
}
echo "</select>";
?>

<?php
// months
$months = array(
'01'=>'一月',
'02'=>'二月',
'03'=>'March',
'04'=>'April',
'05'=>'May',
'06'=>'June',
'07'=>'July',
'08'=>'August',
'09'=>'September',
'10'=>'October',
'11'=>'November',
'12'=>'December',
);
echo "<select id=\"sMonth\" name=\"sMonth\" rel=\"".str_replace(":","\:",$this->getFieldId('month'))."\" class=\"dateselect\">";
$selected = (!$this->getMonth()) ? "selected=\"selected\"" : "";
echo "<option value=\"\" ".$selected.">Month</option>";
foreach ($months as $key=>$var)
{
$selected = ($this->getMonth() == $key) ? "selected=\"selected\"" : "";
echo "<option value=\"".$key."\" ".$selected.">".$var."</option>";
}
echo "</select>";
?>

<?php
// years
$year_end = date('Y');
$year_start = $year_end-99;
echo "<select id=\"sYear\" name=\"sYear\" rel=\"".str_replace(":","\:",$this->getFieldId('year'))."\" class=\"dateselect\">";
$selected = (!$this->getYear()) ? "selected=\"selected\"" : "";
echo "<option value=\"\" ".$selected.">Year</option>";
for ($i = $year_end; $i >= $year_start; $i--) {
$selected = ($this->getYear() == $i) ? "selected=\"selected\"" : "";
echo "<option value=\"".$i."\" ".$selected.">".$i."</option>";
}
echo "</select>";

?>
<div class="input-box customer-dob">

<div class="dob-full" style="display:none;">
<?php echo ' <div class="dob-day">
<input type="hidden" id="' . $this->getFieldId('day') . '" name="' . $this->getFieldName('day') . '" value="' . $this->getDay() . '" title="' . $this->__('Day') . '" class="input-text validate-custom" ' . $this->getFieldParams() . ' />
<label for="' . $this->getFieldId('day') . '">' . $this->__('DD') . '</label>
</div>';?>
<?php echo '
<div class="dob-month">
<input type="hidden" id="' . $this->getFieldId('month') . '" name="' . $this->getFieldName('month') . '" value="' . $this->getMonth() . '" title="' . $this->__('Month') . '" class="input-text validate-custom" ' . $this->getFieldParams() . ' />
<label for="' . $this->getFieldId('month') . '">' . $this->__('MM') . '</label>
</div>'; ?>
<?php echo '
<div class="dob-year">
<input type="hidden" id="' . $this->getFieldId('year') . '" name="' . $this->getFieldName('year') . '" value="' . $this->getYear() . '" title="' . $this->__('Year') . '" class="input-text validate-custom" ' . $this->getFieldParams() . ' />
<label for="' . $this->getFieldId('year') . '">' . $this->__('YYYY') . '</label>
</div>';
?>

<div class="validation-advice" style="display:none;"></div>
</div>
<div class="dob-full" style="display:none;">
<input type="hidden" id="<?php echo $this->getFieldId('dob')?>" name="<?php echo $this->getFieldName('dob')?>" />
</div>

<script type="text/javascript">
//<![CDATA[

var customer_dob = new Varien.DOB('.customer-dob', <?php echo $this->isRequired() ? 'true' : 'false' ?>, '<?php echo $this->getDateFormat() ?>');
jQuery(document).ready(function() {
//加载到hidden input值
jQuery( ".dateselect" ).each(function() {
related_field_id = jQuery(this).attr('rel');
current_value = jQuery( "#"+related_field_id ).val();
jQuery(this).val(current_value);
});
jQuery( "#<?php echo str_replace(":","\:",$this->getFieldId('dob'));?>" ).val(jQuery("#<?php echo str_replace(":","\:",$this->getFieldId('year'));?>").val()+'-'+jQuery("#<?php echo str_replace(":","\:",$this->getFieldId('month'));?>").val()+'-'+jQuery("#<?php echo str_replace(":","\:",$this->getFieldId('day'));?>").val());
// 给dob赋值
jQuery( ".dateselect" ).change(function() {
current_value = jQuery(this).val();
related_field_id = jQuery(this).attr('rel');
jQuery( "#"+related_field_id ).val(current_value);
jQuery( "#<?php echo str_replace(":","\:",$this->getFieldId('dob'));?>" ).val(jQuery("#<?php echo str_replace(":","\:",$this->getFieldId('year'));?>").val()+'-'+jQuery("#<?php echo str_replace(":","\:",$this->getFieldId('month'));?>").val()+'-'+jQuery("#<?php echo str_replace(":","\:",$this->getFieldId('day'));?>").val());
});
});

//]]>
</script>

企鹅magento交流 87 49 38361

转载请注明:爱T-blog » magento 出生日期下拉框 customer dob

与本文相关文章

发表我的评论

取消评论
表情 插代码

Hi,您需要填写昵称和邮箱!

  • 必填项
  • 必填项