Jump to content

Recommended Posts

Hi,

 

First of all im sorry that the only reason i registered is to ask a question, just found out about the php freaks forums  ;D

Anyway, im trying to build a registration form and im a little confused.

 

heres part of the birth date input field:

                    <li>Birth date
                        <select name="day">
                            <option value="">Day</option>
                            <?php
                                $day=1;
                                for($day>=1;$day<32;$day++){
                                    echo '<option value="">'.$day.'</option>';
                                 
                                }
                            ?>
                        </select>
                        <select n1ame="month">
                            <option value="">Month</option>
                            <?php
                                $months=array(Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec);
                                $counter=0;
                                for($counter=0;$counter<=11;$counter++){
                                    echo '<option value="">'.$months[$counter].'</option>';
                                }

                            ?>
                        </select>
                        <select name="year">
                            <option value="">Year</option>
                            <?php
                              $year=date("Y");
                              for($year=$year;$year>=1950;$year--){
                                  echo '<option value="">'.$year.'</option>';
                              }  
                            ?>
                        
                        </select>
                    </li>

my question is, what would the syntax be so i could add $var into the value=" " fields?

 

for example:

echo '<option value="">'.$day.'</option>';

how do i add the $day value inside the <option value=""> aswell?

 

Thanks!

Edited by veilside
Link to comment
https://forums.phpfreaks.com/topic/284371-html-in-echo-tags-issue/
Share on other sites

Variables inside double quotes are translated into their values, so

 <select name="day">
    <option value="">Day</option>
    <?php
        for($day=1;$day<=31;$day++){
            echo "<option value='$day'>$day</option>";
        }
    ?>
</select>
<select name="month">
    <option value="">Month</option>
    <?php
        $months=array(1=>Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec);
        for($counter=1;$counter<=12;$counter++){
            echo "<option value='$counter'>{$months[$counter]}</option>";
        }

    ?>
</select>

 

thanks for the quick response,

 

ive tried your way already but the output would be

<option value=1>1</option>

im trying to make it

<option value="1">1</option>

So put in the double-quotes:

 

echo '<option value=" . '$counter' . ">' . $months[$counter] . '</option>';

 

thanks for the quick response,

 

ive tried your way already but the output would be

<option value=1>1</option>

im trying to make it

<option value="1">1</option>

 

to be precise, my code gives

<option value='1'>1</option>
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.