veilside Posted November 28, 2013 Share Posted November 28, 2013 (edited) 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 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 November 28, 2013 by veilside Quote Link to comment https://forums.phpfreaks.com/topic/284371-html-in-echo-tags-issue/ Share on other sites More sharing options...
Barand Posted November 28, 2013 Share Posted November 28, 2013 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> Quote Link to comment https://forums.phpfreaks.com/topic/284371-html-in-echo-tags-issue/#findComment-1460581 Share on other sites More sharing options...
veilside Posted November 29, 2013 Author Share Posted November 29, 2013 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> Quote Link to comment https://forums.phpfreaks.com/topic/284371-html-in-echo-tags-issue/#findComment-1460582 Share on other sites More sharing options...
cyberRobot Posted November 29, 2013 Share Posted November 29, 2013 What does your updated code look like? Quote Link to comment https://forums.phpfreaks.com/topic/284371-html-in-echo-tags-issue/#findComment-1460590 Share on other sites More sharing options...
aysiu Posted November 29, 2013 Share Posted November 29, 2013 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>'; Quote Link to comment https://forums.phpfreaks.com/topic/284371-html-in-echo-tags-issue/#findComment-1460591 Share on other sites More sharing options...
Barand Posted November 29, 2013 Share Posted November 29, 2013 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> Quote Link to comment https://forums.phpfreaks.com/topic/284371-html-in-echo-tags-issue/#findComment-1460610 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.