teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

4

インデント

2018/07/05 11:15

投稿

P_Beginner
P_Beginner

スコア99

title CHANGED
File without changes
body CHANGED
@@ -69,26 +69,26 @@
69
69
  if(select1.options[select1.selectedIndex].value==year||select2.options[select2.selectedIndex].value==month){
70
70
  for(i=1;i<=day;i++)
71
71
  select3.options[i-1] = new Option(i);
72
- }
73
- if(select2.options[select2.selectedIndex].value==4||select2.options[select2.selectedIndex].value==6||select2.options[select2.selectedIndex].value==9||select2.options[select2.selectedIndex].value==11){
72
+ }
73
+ if(select2.options[select2.selectedIndex].value==4||select2.options[select2.selectedIndex].value==6||select2.options[select2.selectedIndex].value==9||select2.options[select2.selectedIndex].value==11){
74
74
  for(i=1;i<=30;i++)
75
75
  select3.options[i-1] = new Option(i);
76
- }
76
+ }
77
- else if (select2.options[select2.selectedIndex].value==2){
77
+ else if (select2.options[select2.selectedIndex].value==2){
78
- if((select1.options[select1.selectedIndex].value%4==0&&select1.options[select1.selectedIndex].value%100!=0)||select1.options[select1.selectedIndex].value%400==0){
78
+ if((select1.options[select1.selectedIndex].value%4==0&&select1.options[select1.selectedIndex].value%100!=0)||select1.options[select1.selectedIndex].value%400==0){
79
- for(i=1;i<=29;i++)
79
+ for(i=1;i<=29;i++)
80
80
  select3.options[i-1] = new Option(i);
81
- }
81
+ }
82
- else{
82
+ else{
83
- for(i=1;i<=28;i++)
83
+ for(i=1;i<=28;i++)
84
- select3.options[i-1] = new Option(i);
84
+ select3.options[i-1] = new Option(i);
85
- }
85
+ }
86
- }
86
+ }
87
- else{
87
+ else{
88
- for(i=1;i<=31;i++)
88
+ for(i=1;i<=31;i++)
89
- select3.options[i-1] = new Option(i);
89
+ select3.options[i-1] = new Option(i);
90
- }
90
+ }
91
- }
91
+ }
92
92
  </script>
93
93
  <input type="submit" value="送信">
94
94
  </form>

3

補足

2018/07/05 11:15

投稿

P_Beginner
P_Beginner

スコア99

title CHANGED
File without changes
body CHANGED
@@ -6,6 +6,7 @@
6
6
  (1) 存在する年月日のみが選択できること(=2月30日,4月31日などは選択できないこと)
7
7
  (2) 閏年が考慮されていること(=2月が28日までのものと29までのものが存在)
8
8
  (3) 現在までの年月日のみが選択できること(=未来は選択できないこと)
9
+ (4) 補足:送信ボタンを押した後に,自分自身に帰ってくる場合(action="index.php")に押下した値がリセットされずに残っているとなお良い
9
10
 
10
11
  実際に自分で考えてみて,下のようになりました.
11
12
  bodyタグを含め,その中身を貼ります.

2

補足

2018/07/05 11:10

投稿

P_Beginner
P_Beginner

スコア99

title CHANGED
File without changes
body CHANGED
@@ -74,7 +74,7 @@
74
74
  select3.options[i-1] = new Option(i);
75
75
  }
76
76
  else if (select2.options[select2.selectedIndex].value==2){
77
- if((select1.options[select1.selectedIndex].value%4==0&&select1.options[select1.selectedIndex].value%10!=0)||select1.options[select1.selectedIndex].value%400==0){
77
+ if((select1.options[select1.selectedIndex].value%4==0&&select1.options[select1.selectedIndex].value%100!=0)||select1.options[select1.selectedIndex].value%400==0){
78
78
  for(i=1;i<=29;i++)
79
79
  select3.options[i-1] = new Option(i);
80
80
  }

1

インデントを加え補足した

2018/07/05 11:05

投稿

P_Beginner
P_Beginner

スコア99

title CHANGED
File without changes
body CHANGED
@@ -13,79 +13,81 @@
13
13
 
14
14
  条件分岐は(1)〜(3)を考慮しようと付けたものです.
15
15
 
16
+ イメージ的にはyear,month,dayに現在年月日を,
17
+ selectYear,selectMonth,selectDayに選択年月日を入れてプログラムを組んだつもりです.
16
18
 
17
19
  ```HTML
18
20
  <body>
19
21
  <center>
20
22
  <body bgcolor onLoad="dateFunc()">
21
- <img src="LOGO.png" alt="">
23
+ <img src="LOGO.png" alt="">
22
- <h2>タイトル</h2>
24
+ <h2>見出し</h2>
23
- <?php
25
+ <?php
24
- date_default_timezone_set('Asia/Tokyo');
26
+ date_default_timezone_set('Asia/Tokyo');
25
- $year=filter_input(INPUT_GET,'year')?:date('Y');
27
+ $year=filter_input(INPUT_GET,'year')?:date('Y');
26
- $month=filter_input(INPUT_GET,'month')?:date('n');
28
+ $month=filter_input(INPUT_GET,'month')?:date('n');
27
- $day=filter_input(INPUT_GET,'day')?:date('j');
29
+ $day=filter_input(INPUT_GET,'day')?:date('j');
28
- ?>
30
+ ?>
29
- <form name="selectDate" method="get">
31
+ <form name="selectDate" method="get">
30
- <select name="selectYear">
32
+ <select name="selectYear">
31
- <?php
33
+ <?php
32
- for($i=2015;$i<=date('Y');$i++){
34
+ for($i=2015;$i<=date('Y');$i++){
33
- $selected=$i==$year?"selected":"";
35
+ $selected=$i==$year?"selected":"";
34
- print "<option value=\"{$i}\"{$selected}>{$i}</option>";
36
+ print "<option value=\"{$i}\"{$selected}>{$i}</option>";
35
- }
37
+ }
36
- ?>
38
+ ?>
37
- </select> 年
39
+ </select> 年
38
- <select name="selectMonth">
40
+ <select name="selectMonth">
39
- </select> 月
41
+ </select> 月
40
- <select name="selectDay">
42
+ <select name="selectDay">
41
- </select> 日
43
+ </select> 日
42
44
 
43
- <script type="text/javascript">
45
+ <script type="text/javascript">
44
- var year='<?php echo $year; ?>';
46
+ var year='<?php echo $year; ?>';
45
- var month='<?php echo $month; ?>';
47
+ var month='<?php echo $month; ?>';
46
- var day='<?php echo $day; ?>';
48
+ var day='<?php echo $day; ?>';
47
- function dateFunc(){
49
+ function dateFunc(){
48
- var select1 = document.forms.selectDate.selectYear;
50
+ var select1 = document.forms.selectDate.selectYear;
49
- var select2 = document.forms.selectDate.selectMonth;
51
+ var select2 = document.forms.selectDate.selectMonth;
50
- var select3 = document.forms.selectDate.selectDay;
52
+ var select3 = document.forms.selectDate.selectDay;
51
53
 
52
- select2.options.length=0;
54
+ select2.options.length=0;
53
- select3.options.length=0;
55
+ select3.options.length=0;
54
56
 
55
- if(select1.options[select1.selectedIndex].value==year){
57
+ if(select1.options[select1.selectedIndex].value==year){
56
- for(i=1;i<=month;i++){
58
+ for(i=1;i<=month;i++){
57
- select2.options[i-1] = new Option(i);
59
+ select2.options[i-1] = new Option(i);
58
- }
60
+ }
59
- }
61
+ }
60
- else{
62
+ else{
61
- for(i=1;i<=12;i++){
63
+ for(i=1;i<=12;i++){
62
- select2.options[i-1] = new Option(i);
64
+ select2.options[i-1] = new Option(i);
63
- }
65
+ }
64
- }
66
+ }
65
67
 
66
- if (select1.options[select1.selectedIndex].value==year||select2.options[select2.selectedIndex].value==month){
67
- for(i=1;i<=day;i++)
68
- select3.options[i-1] = new Option(i);
69
- }
70
- if(select2.options[select2.selectedIndex].value==4||select2.options[select2.selectedIndex].value==6||select2.options[select2.selectedIndex].value==9||select2.options[select2.selectedIndex].value==11){
71
- for(i=1;i<=30;i++)
72
- select3.options[i-1] = new Option(i);
73
- }
74
- else if (select2.options[select2.selectedIndex].value==2){
75
- if((select1.options[select1.selectedIndex].value%4==0&&select1.options[select1.selectedIndex].value%10!=0)||select1.options[select1.selectedIndex].value%400==0){
76
- for(i=1;i<=29;i++)
77
- select3.options[i-1] = new Option(i);
78
- }
79
- else{
80
- for(i=1;i<=28;i++)
81
- select3.options[i-1] = new Option(i);
82
- }
83
- }
84
- else{
85
- for(i=1;i<=31;i++)
86
- select3.options[i-1] = new Option(i);
87
- }
88
- }
68
+ if(select1.options[select1.selectedIndex].value==year||select2.options[select2.selectedIndex].value==month){
69
+ for(i=1;i<=day;i++)
70
+ select3.options[i-1] = new Option(i);
71
+ }
72
+ if(select2.options[select2.selectedIndex].value==4||select2.options[select2.selectedIndex].value==6||select2.options[select2.selectedIndex].value==9||select2.options[select2.selectedIndex].value==11){
73
+ for(i=1;i<=30;i++)
74
+ select3.options[i-1] = new Option(i);
75
+ }
76
+ else if (select2.options[select2.selectedIndex].value==2){
77
+ if((select1.options[select1.selectedIndex].value%4==0&&select1.options[select1.selectedIndex].value%10!=0)||select1.options[select1.selectedIndex].value%400==0){
78
+ for(i=1;i<=29;i++)
79
+ select3.options[i-1] = new Option(i);
80
+ }
81
+ else{
82
+ for(i=1;i<=28;i++)
83
+ select3.options[i-1] = new Option(i);
84
+ }
85
+ }
86
+ else{
87
+ for(i=1;i<=31;i++)
88
+ select3.options[i-1] = new Option(i);
89
+ }
90
+ }
89
91
  </script>
90
92
  <input type="submit" value="送信">
91
93
  </form>