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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.