Jump to content

Need help with php generated drop down list using date()


offsprg01

Recommended Posts

here's the code

 

				<select name="YEAR" size="1" style="width:100px">
				  <?php
				  	$current_year = date("Y");
					do {?>
						<option value="<?php echo $current_year; ?>" 
						<?php if ($yearText == $current_year) {?>
							selected="selected"> <?php echo $current_year; ?> </option>
						<?php } 
					while ($current_year != 2001);

				  ?>					  
				 </select>

 

am i doing this correctly? i think i am but apparently i'm not.

It's just selected, not selected="selected".

 

What are you trying to do that isn't working? You never increment the year.

This could be accomplished with a slightly shorter for loop.

 

for($i=2001; $i<=date("Y"); $i++){
   print '<option value="'.$i.'"';
   if($yearText == $i){
      print ' selected';
   }
   print '>'.$i.'</option>';
}

That would be javascript, and kind of worthless in time. You're going to have to check it serverside anyway with valid_date() (or whatever it is) so just go for 1-31 and give them an error after the fact if they mess with it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.