hiding select element
Posted: Mon Apr 22, 2013 1:24 pm
Ok i want to setup select boxes for year, month and day. it starts with only year showing. when anything other than index0 is selected them month appears. same for that then day appears. if i set month back to index0 then day resets to index0 and hides itself like i want. however when i set year to index0 the month resets and hides but the day only resets and doesnt hide.
Code: Select all
<?php
include 'servlog.php';
if (isset($_POST['add'])) {
if (is_numeric(mysql_real_escape_string($_POST['logyear']))){$lys = mysql_real_escape_string($_POST['logyear']);}
if (is_numeric(mysql_real_escape_string($_POST['logmonth']))){$lms = mysql_real_escape_string($_POST['logmonth']);}
if (is_numeric(mysql_real_escape_string($_POST['logday']))){$lds = mysql_real_escape_string($_POST['logday']);}
}
?>
<script type="text/javascript">
function fromDate(){
var yx=document.getElementById("logyear").selectedIndex;
var mx=document.getElementById("logmonth").selectedIndex;
if (yx != 0){
document.getElementById('logmonth').style.display="inline";
document.getElementById('logmonth').disabled=false;
}
else {
document.logfilters.logday.selectedIndex = "0";
document.getElementById('logday').style.display="none";
document.getElementById('logday').disabled=true;
document.logfilters.logmonth.selectedIndex = "0";
document.getElementById('logmonth').style.display="none";
document.getElementById('logmonth').disabled=true;
}
if (mx != 0){
document.getElementById('logday').style.display="inline";
document.getElementById('logday').disabled=false;
}
else {
document.logfilters.logday.selectedIndex = "0";
document.getElementById('logday').style.display="none";
document.getElementById('logday').disabled=true;
}
}
</script>
<form name="logfilters" action="" method="post">
<select id="logyear" name="logyear" onchange="fromDate()">
<option value="">YEAR</option>
<?php $staryear = 2010;
$endyear = date('Y');
for ($sy=$staryear; $sy<=$endyear; $sy++){?>
<option value="<?=$sy?>" <?php if ($lys == $sy){ echo "selected='selected'";} ?>><?=$sy?></option>
<?php }?>
</select>
<select id="logmonth" name="logmonth" style="display:none" disabled="disabled" onchange="fromDate()">
<option value="">MONTH</option>
<?php $starmonth = 1;
$endmonth = 12;
for ($sm=$starmonth; $sm<=$endmonth; $sm++){?>
<option value="<?=$sm?>" <?php if ($lms == $sm){ echo "selected='selected'";} ?>><?=$sm?></option>
<?php }?>
</select>
<select id="logday" name="logday" style="display:none" disabled="disabled">
<option value="">DAY</option>
<?php $starday = 1;
$endday = 31;
for ($sd=$starday; $sd<=$endday; $sd++){?>
<option value="<?=$sd?>" <?php if ($lds == $sd){ echo "selected='selected'";} ?>><?=$sd?></option>
<?php }?>
</select>
<br />
<input type="submit" name="add" value="Sort" />
</form>