Jump to content

Initialiuze Select Box


natalieG

Recommended Posts

WE have a sewlect box in a form that we are trying to initialize in an edit foirm. The code
we tried is below. The select box window does not change when we set the selected value,Is
there a way to have it change and thgen transmit the new vakue when firm is submitter?

Thanks,

Natalie


<select name="MONTH" size="1">
<option selected value="<?php echo $MO ?>">Jan</option>
<option value="02">Feb</option>
<option value="03">Mar</option>
<option value="04">Apr</option>
<option value="05">May</option>
<option value="07">Jul</option>
<option value="07">Jul</option>
<option value="08">Aug</option>
<option value="09">Sep</option>
<option value="10">Oct</option>
<option value="12">Dec</option>
<option value="11">Nov</option>
Link to comment
https://forums.phpfreaks.com/topic/10969-initialiuze-select-box/
Share on other sites

[code]
<?php
$initMO = "01"; // Jan
$month = array();
$month ['01'] = 'Jan';$month ['02'] = 'Feb';$month ['03'] = 'Mar';$month ['04'] = 'Apr';
$month ['05'] = 'May';$month ['06'] = 'Jul';$month ['07'] = 'Jun';$month ['08'] = 'Aug';
$month ['09'] = 'Sep';$month ['10'] = 'Oct';$month ['11'] = 'Nov';$month ['12'] = 'Dec';

?>
<select name="MONTH" size="1">
<?php foreach($month as $mo =>$key) {?>
   <option selected value= <?=$key?> <?php if($key == $initMo)echo "selected"; ?><?= $mo ?></option>
<?php } /* End foreach loop */ ?>
[/code]


The above code will allow you to initialize the month to wahtever you set the $initMO to and will keep to your "01", "02" standards..

edit: whops, used "checked" instead of "selected"
Chris
Link to comment
https://forums.phpfreaks.com/topic/10969-initialiuze-select-box/#findComment-40957
Share on other sites

[!--quoteo(post=379143:date=Jun 1 2006, 02:56 PM:name=natalieG)--][div class=\'quotetop\']QUOTE(natalieG @ Jun 1 2006, 02:56 PM) [snapback]379143[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Hi-

We tried the code and it gave us a message that initMo was an undeclared variable
in each line of the selkectbox
[/quote]

ah, my bad, change the $initMO at the top to $initMo
that will fix it for you
Link to comment
https://forums.phpfreaks.com/topic/10969-initialiuze-select-box/#findComment-41142
Share on other sites

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.