Set default value for select input in php -
i want set default value @ "-24hours". options dynamically generated foreach.
<select id="search3" name="date" onchange='this.form.submit();'> <?php $orderby_options3 = array( '-3day' => 'last 3 days', '-48hours' => '48 hours', '-24hours' => '24 hours', ); foreach( $orderby_options3 $value3 => $label3 ) { echo "<option ".selected( $_get['date'], $value3 )." value='$value3'>$label3</option>"; } ?> </select>
i know should add "selected" parameter option in case, it's not possible.
if want -24hours selected , page won't used edit page, can this:
<select id="search3" name="date" onchange='this.form.submit();'> <?php $orderby_options3 = array( '-3day' => 'last 3 days', '-48hours' => '48 hours', '-24hours' => '24 hours', ); foreach( $orderby_options3 $value3 => $label3 ) { $select = ($value3 == '-24hours') ? "selected='selected'":""; // see line echo "<option ".selected( $_get['date'], $value3 )." value='$value3' $select>$label3</option>"; } ?>
Comments
Post a Comment