Jump to content


Photo

Initialiuze Select Box


  • Please log in to reply
3 replies to this topic

#1 natalieG

natalieG
  • Members
  • PipPipPip
  • Advanced Member
  • 63 posts

Posted 01 June 2006 - 04:15 PM

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>

#2 lead2gold

lead2gold
  • Members
  • PipPipPip
  • Advanced Member
  • 164 posts
  • LocationOttawa, On

Posted 01 June 2006 - 04:44 PM

<?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 */ ?>


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

#3 natalieG

natalieG
  • Members
  • PipPipPip
  • Advanced Member
  • 63 posts

Posted 01 June 2006 - 06:56 PM

Hi-

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

#4 lead2gold

lead2gold
  • Members
  • PipPipPip
  • Advanced Member
  • 164 posts
  • LocationOttawa, On

Posted 02 June 2006 - 12:18 PM

[!--quoteo(post=379143:date=Jun 1 2006, 02:56 PM:name=natalieG)--][div class=\'quotetop\']QUOTE(natalieG @ Jun 1 2006, 02:56 PM) View Post[/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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users