테스트 사이트 - 개발 중인 베타 버전입니다

selectbox 선택했던 그대로 유지하고 싶습니다. 채택완료

둠둠 8년 전 조회 3,170

<script type="text/javascript"> function ok_ttt(_year, _month){ document.getElementsByName("toYear")[0].value = $("#year1").val(); document.getElementsByName("toMonth")[0].value = _month; //alert($('input[name="toYear"]').val()); document.ft.submit(); } </script>


<?

if($R['year1'] && $R['month1']) {

$year1 = $R['year1'];

$month1 = $R['month1'];

} else {

$year1 = substr($date['today'],0,4);

$month1 = substr($date['today'],4,2);

}

?>



<td class="fa fa-angle-left fa-lg">

<select name="year1" id="year1">

<?php for($i=$date['year']-6;$i<$date['year']+1;$i++):?>

<option value="<?php echo $i?>"<?php if($year1==$i):?> selected="selected"<?php endif?>>

<?php echo $i?>

</option><?php endfor?>

</select>

<select name="month1" onChange="ok_ttt('<?=$_year_l?>',this.value)">

<?php for($i=1;$i<13;$i++):?>

<option value="<?php echo sprintf('%02d',$i)?>"<?php if($month1==$i):?> selected="selected"<?php endif?>>

<?php echo sprintf('%02d',$i)?>

</option><?php endfor?>

</select>

</td>


select box 이용해서 바로 페이지 이동하게끔 했습니다.


처음 홈페이지에 들어가면 오늘날짜인 2017년 8월이 떠있어야합니다. 


저 소스로 하니 오늘날짜가 자동으로 뜹니다


문제는 2016년 7월을 선택했을 때


selectbox 내의 숫자가 다시 오늘날짜인 2017년 8월로 돌아가버립니다.


현재 화면에서 새로고침되면서 결과값이 나오고 있습니다.


원하는 날짜를 선택했을때 그 날짜가 새로고침됐어도 그대로 유지되게끔 하고싶습니다.


댓글을 작성하려면 로그인이 필요합니다.

답변 3개

채택된 답변
+20 포인트
l
8년 전

$_GET['toMonth'] 값이 1월 ~ 9월일때 

01, 02.. 와 같은 값이 아니라 1, 2 와 같은 값이 전달되고 있다면

</span></p><p style="word-break: break-all; color: rgb(80, 80, 80); font-family: Arial, 돋움, Dotum; font-size: 14.004px;">if ($_GET['toYear'] && $_GET['toMonth']) {</p><p style="word-break: break-all; color: rgb(80, 80, 80); font-family: Arial, 돋움, Dotum; font-size: 14.004px;">    $year1 = $_GET['toYear'];</p><p style="word-break: break-all; color: rgb(80, 80, 80); font-family: Arial, 돋움, Dotum; font-size: 14.004px;">    $month1 = strlen($_GET['toMonth']) === 1 ? '0'.<span style="font-size: 14.004px;">$_GET['toMonth'] : </span><span style="font-size: 14.004px;">$_GET['toMonth']</span><span style="font-size: 14.004px;"> ;</span></p><p style="word-break: break-all; color: rgb(80, 80, 80); font-family: Arial, 돋움, Dotum; font-size: 14.004px;">} else {</p><p style="word-break: break-all; color: rgb(80, 80, 80); font-family: Arial, 돋움, Dotum; font-size: 14.004px;"><span style="font-size: 11pt;">    $year1 = date('Y');</span></p><p style="word-break: break-all; color: rgb(80, 80, 80); font-family: Arial, 돋움, Dotum; font-size: 14.004px;">    $month1 = date('m');</p><p style="word-break: break-all; color: rgb(80, 80, 80); font-family: Arial, 돋움, Dotum; font-size: 14.004px;">}</p><p style="word-break: break-all; color: rgb(80, 80, 80); font-family: Arial, 돋움, Dotum; font-size: 14.004px;"><span style="font-size: 14.004px;">
 

와 같이 소스를 변경해 보세요

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

플라이
8년 전

변수가 제대로 전달이 되어 반영되고 있는지 확인이 필요합니다.

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

l
8년 전

변경된 값을 아래의 경우중 하나를 선택해서 저장하고

해당값은 저장된 값에서 불러오되 없으면 기본값으로 설정

1. 세션

2. 쿠키

3. DB

4. URL (GET 방식)

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인