Jump to content

Recommended Posts

Hi, i have a very quick problem;

 

I have my selectbox in HTML on an "edit account" page.

 

      <select name="mm" id="mm">
      <option value="1">January</option>
      <option value="2">February</option>
      <option value="3">March</option>
      <option value="4">April</option>
      <option value="5">May</option>
      <option value="6">June</option>
      <option value="7">July</option>
      <option value="8">August</option>
      <option value="9">September</option>
      <option value="10">October</option>
      <option value="11">November</option>
      <option value="12">December</option>
          </select>

 

For normal fields i am doing this;

<input type="text" name="email" maxlength="50" value="
<?
if($form->value("email") == ""){
   echo $session->userinfo['email'];
}else{
   echo $form->value("email");
}
?>">

 

How would i work this on a selectbox field?

Link to comment
https://forums.phpfreaks.com/topic/129121-select-boxes-with-mysql/
Share on other sites

Here are 2 that I used for month and day.  This should help you out I think...

 

	<td width="79%"><select size="1" name="billing_renew_month">
 <option<?php if ($month_of_year == 1) echo " SELECTED"; ?> value="1">January</option>
 <option<?php if ($month_of_year == 2) echo " SELECTED"; ?> value="2">February</option>
 <option<?php if ($month_of_year == 3) echo " SELECTED"; ?> value="3">March</option>
 <option<?php if ($month_of_year == 4) echo " SELECTED"; ?> value="4">April</option>
 <option<?php if ($month_of_year == 5) echo " SELECTED"; ?> value="5">May</option>
 <option<?php if ($month_of_year == 6) echo " SELECTED"; ?> value="6">June</option>
 <option<?php if ($month_of_year == 7) echo " SELECTED"; ?> value="7">July</option>
 <option<?php if ($month_of_year ==  echo " SELECTED"; ?> value="8">August</option>
 <option<?php if ($month_of_year == 9) echo " SELECTED"; ?> value="9">September</option>
 <option<?php if ($month_of_year == 10) echo " SELECTED"; ?> value="10">Ocotober</option>
 <option<?php if ($month_of_year == 11) echo " SELECTED"; ?> value="11">November</option>
 <option<?php if ($month_of_year == 12) echo " SELECTED"; ?> value="12">December</option>
</select>  
<select size="1" name="billing_renew_day"><?php

//write out all the options for 1-31 days
for ($jj = 1; $jj < 32; $jj++)
{
	echo "\n\t <option ";
	if ($day_of_month == $jj)
		echo "SELECTED ";
	echo "value\"=".$jj."\">".$jj."</option>";
}?>

 

Try that out and see if that helps your situation.

Also try this.  This will 100% automate writing out all of the names of the month so you don't have to manually type them out...

 

<?php	for ($i = 1; $i < 13; $i++)
{
	echo "\n\t <option ";
	if ($month_of_year == $i)
		echo "SELECTED ";
	echo "value\"=".$i."\">".date("F", $i)."</option>";
}?>

Change

echo "value\"=".$jj."\">".$jj."</option>";

to

sprintf('value="%02d">%02d</option>', $jj);

 

I'm getting this error;

sprintf() [<a href='function.sprintf'>function.sprintf</a>]: Too few arguments in <b>/home/altshop/public_html/new/useredit.php</b> on line <b>132</b><br />

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.