Solved

how to bring in list box combining html & php?

Posted on 2002-06-04
7
237 Views
Last Modified: 2008-03-17
hai all,
my html file has foll coding, the file saved as php.
I try to get list box using foll coding.But from option 10 it uses php to list it down.but I get only until 9. it cannot go beyond 10.Can anyone tell me where I went wrong & provide me the solution

<?php
?>
//some html codes
<td align="center"><font face="Arial, Helvetica, sans-serif" size="2">
<select name="gd1"size="1" onFocus="selfclick(2)">
                <option value="01">1</option>
                <option value="02">2</option>
                <option value="03">3</option>
                <option value="04">4</option>
                <option value="05">5</option>
                <option value="06">6</option>
                <option value="07">7</option>
                <option value="08">8</option>
                <option value="09">9</option>
                <?
                 for ($i=10;$i<=31;$i++)
                 echo("<option value=".$i.">".$i."</option>");
?>
              </select>
              </font> </td>
0
Comment
Question by:baska
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 5

Expert Comment

by:dkjariwala
ID: 7053408
Check this,

<?php
?>
//some html codes
<td align="center"><font face="Arial, Helvetica, sans-serif" size="2">
<select name="gd1"size="1" onFocus="selfclick(2)">
               <option value="01">1</option>
               <option value="02">2</option>
               <option value="03">3</option>
               <option value="04">4</option>
               <option value="05">5</option>
               <option value="06">6</option>
               <option value="07">7</option>
               <option value="08">8</option>
               <option value="09">9</option>
               <?
                for ($i=10;$i<=31;$i++)
                    {
                         print "<option value=\"$i\">$i</option>";
                    }

?>

JD
0
 
LVL 5

Accepted Solution

by:
dkjariwala earned 50 total points
ID: 7053410
Btw, you can just make it simple by doing,

<?php
?>
//some html codes
<td align="center"><font face="Arial, Helvetica, sans-serif" size="2">
<select name="gd1"size="1" onFocus="selfclick(2)">

               <?
                for ($i=1;$i<=31;$i++)
                    {
                         if($i<10)
                              $value = "0" . $i;
                         else
                              $value = $i;
                         print "<option value=\"$value\">$i</option>\n";
                    }

?>



JD
0
 
LVL 32

Expert Comment

by:Batalf
ID: 7053551
or simply:

<?php
?>
//some html codes
<td align="center"><font face="Arial, Helvetica, sans-serif" size="2">
<select name="gd1"size="1" onFocus="selfclick(2)">
               <?
                for ($i=1;$i<=31;$i++)
{
  if($i<10)$prefix="0";else $prefix="";
                echo("<option value=\"".$prefix$i."\">".$i."</option>");

}?>
             </select>
             </font> </td>
0
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

 
LVL 32

Expert Comment

by:Batalf
ID: 7053552
Sorry dkjariwala : Caching problem on my PC I guess. Didn't see your last comment.
0
 
LVL 5

Expert Comment

by:dkjariwala
ID: 7053562
NP.

JD
0
 
LVL 5

Expert Comment

by:Hamlet081299
ID: 7055052
I think dkjariwala has already answer the question, but just one slight improvement I would suggest is to replace...

                        if($i<10)
                             $value = "0" . $i;
                        else
                             $value = $i;

... with ...
                        $value = sprintf('%02d', $i);



Also as a side note.... I'm guessing that maybe this is something to do with giving the user a way to select a date.  If that's the case I suggest you check out the PEAR Calendar functions, there's some really handy functions that make date handling much easier.
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 7055826
Can you try changing the value in the size option on the Select tag to 2?

Regards,

Richard.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question