Jump to content

Html in echo tags issue


veilside

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!

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>

Archived

This topic is now archived and is closed to further replies.

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