php
1 2画像1.画像2のように非表示の状態からプルダウンメニューで選択し、 3javascriptを使い内容を表示させたいです。 4 5 6送信ボタンに関数をあてがいましたが上手くいきませんでした。。。 7初歩的な質問で申し訳ないですが、ご親切な方おりましたらご教授いただけないでしょうか?よろしくお願いいたします。 8 9 10 11<?php 12$d = date('Y/m'); 13list($year, $month) = explode('/', $d); 14$thisYear=$year; 15 16if(isset($_POST['year'])) $year = $_POST['year'];//isset変数:有true無false 17if(isset($_POST['month'])) $month = $_POST['month']; 18 19$optionYear = ""; 20for ($i=($thisYear-10); $i<=($thisYear+10); $i++) { 21 $selected = ($i == $year)?" selected":"";//真:selected 偽:""空 //三項演算子 22 $optionYear .= '<option value="' . $i . '"' . $selected . '>' . $i . '</option>' . "\n"; 23} 24$optionMonth=""; 25for($i=1;$i<=12; $i++) { 26 $selected=($i==$month)?" selected":""; 27 $optionMonth .= '<option value="' . $i . '"' . $selected . '>' . $i . '</option>' . "\n"; 28} 29$weekday = array ('日' ,'月' ,'火' ,'水' ,'木' ,'金' ,'土' ); 30 31$s = '<table border="1"><tr>'; 32for($i = mktime(0 ,0 , 0, $month, 1,$year);$i<mktime(0, 0, 0, $month+1 ,1 ,$year);$i+=60*60*24) {//タイムスタンプmktime,加算代入 33 $s .= "<td>".date('Y/m/d',$i)."</td><td>".$weekday[date('w',$i)]."</td></tr>"; 34} 35$s .= "</table>"; 36//var_dump($s); 37?> 38<!doctype html> 39<html> 40<head> 41<meta charset="UTF-8"> 42<title>日付曜日</title> 43</head> 44<h2>日付(選択出力)</h2> 45<form method="post"> 46<select name="year"><?php echo $optionYear; ?></select>年 47<select name="month"><?php echo $optionMonth; ?></select>月 48<input type="submit" name="btn" value="送信" onClick="show"> 49</form> 50<p id= "disp" class="hyoji" <?php echo $s; ?></p> 51</body> 52<style> 53.hyoji { 54display: none; 55} 56</style> 57 58<script type="text/javascript"> 59function show() { 60 //alert('A'); 61 document.getElementById("disp").style.display="block"; 62} 63</script> 64</html> 65コード
回答3件
あなたの回答
tips
プレビュー