0
我在Drupal中有这种形式,它包含两个日期选择器和两个文本框。我需要编写一个函数来更新两个文本字段中的值。所以在textfield first_result我需要添加35天,并在textfield second_result我需要添加3个月,并设置这些值在两个文本框,并在datepicker due_date我需要更新此字段添加一年45天:javascript功能日期
我的代码:
<?php
drupal_add_js(drupal_get_path('module', 'Date') .'/script.js');
function Pregnancy_menu() {
$items['form/Date'] = array(
'title' => 'Date Calculator',
'page callback' => 'drupal_get_form',
'page arguments' => array('Date_form'),
'access callback' => TRUE,
);
return $items;
}
function Date_form($form_type) {
drupal_add_js(drupal_get_path('module', 'Date') .'/script.js');
$form['First_Period'] = array(
'#type' => 'date_popup',
'#title' => 'Date of your last menstrual period',
'#date_format' => 'Y-m-d',
'#date_text_parts' => array('year'),
'#date_increment' => 30,
'#date_year_range' => '-1:0',
'#default_value' => date(Y) . date(M) . date(D),
);
$form['Calculate_Forward'] = array(
'#type' => 'button',
'#value' => t('Calculate Forward'),
'#attributes' => array('onclick' => "testing()"),
);
$form['Reset_form'] = array(
'#name' => 'clear',
'#type' => 'button',
'#value' => t('Reset this Form'),
'#attributes' => array('onclick' => 'this.form.reset(); return false;'),
);
$form['First_result'] = array(
'#type' => 'textfield',
'#title' => t('first result'),
'#prefix' => '<div style="float:left;">',
'#suffix' => '</div>',
'#default_value' => 'Hello',
);
$form['Second_result'] = array(
'#type' => 'textfield',
'#title' => t('second result'),
'#prefix' => '<div style="float:left;">',
'#suffix' => '</div>',
);
$form['Due_Date'] = array(
'#type' => 'date_popup',
'#title' => 'Estimated Due Date',
'#date_format' => 'Y-m-d',
'#date_text_parts' => array('year'),
'#date_increment' => 30,
'#date_year_range' => '+1:+1',
'#default_value' => date(Y) . date(M) . date(D),
);
return $form;
}
// JavaScript函数的script.js
var testing()=function()
{
//how to do the calculation here
}
我怎样才能读取的形式作为输入的日期值。要将日期从字符串转换为日期值 – sally
@sally,我没有在我的drupal上更新日期,但是在JS端,只需使用Date.parse(document.getElementById(dateFieldId));'。 – Lucas