chaseman Posted February 26, 2011 Share Posted February 26, 2011 Since I didn't want to type it out myself I wrote a small Date of Birth drop down menu generator. Now I'm wondering how I can make the code copy-able in a text area? The script should be inserting all the code ready and finished into a textarea so you can copy and go. How is it done? Here's the script: <?php echo "<center>"; ?> <form action='' method='POST'> <input type='submit' name='submit' /> </form> <?php $submit = $_POST['submit']; if ($submit) { echo "<form action='' method='POST'>"; echo "<select name='month'>"; for ($m = 01; $m <= 12; $m++) { echo " <option value='" . $m . "'>" . $m . "</option> "; } echo "</select>"; echo "<select name='day'>"; for ($d = 01; $d <= 31; $d++) { echo " <option value='" . $d . "'>" . $d . "</option> "; } echo "</select>"; echo "<select name='year'>"; for ($y = 1900; $y <= 2010; $y++) { echo " <option value='" . $y . "'>" . $y . "</option> "; } echo "</select>"; echo "</form>"; echo "</center>"; } ?> Link to comment https://forums.phpfreaks.com/topic/228921-small-date-of-birth-menu-generator-i-wrote-how-to-make-code-copy-able/ Share on other sites More sharing options...
chaseman Posted February 26, 2011 Author Share Posted February 26, 2011 Putting a variable inside the echo works like so: echo $code1 = "<form action='' method='POST'>"; And then inserting it into a textarea like so: <form action='' method='POST'> <textarea type='text' name='codecopy'> <?php echo $code1; echo $code2; echo $code3; echo $code4; echo $code5; ?> </textarea> </form> The only problem I'm having is, that this: for ($m = 01; $m <= 12; $m++) { echo $code3 = " <option value='" . $m . "'>" . $m . "</option> "; } Will output the last set number, which is 12 like this: <form action='' method='POST'><select name='month'> <option value='12'>12</option> </select></form> Any suggestion? Link to comment https://forums.phpfreaks.com/topic/228921-small-date-of-birth-menu-generator-i-wrote-how-to-make-code-copy-able/#findComment-1179984 Share on other sites More sharing options...
chaseman Posted February 26, 2011 Author Share Posted February 26, 2011 Ok I solved this problem with a function echo "<center>"; ?> <form action='' method='POST'> <input type='submit' name='submit' /> </form> <?php $submit = $_POST['submit']; if ($submit) { function dob_generate () { echo "<form action='' method='POST'>"; echo "<select name='month'>"; for ($m = 01; $m <= 12; $m++) { echo " <option value='" . $m . "'>" . $m . "</option> "; } echo "</select>"; echo "<select name='day'>"; for ($d = 01; $d <= 31; $d++) { echo " <option value='" . $d . "'>" . $d . "</option> "; } echo "</select>"; echo "<select name='year'>"; for ($y = 1900; $y <= 2010; $y++) { echo " <option value='" . $y . "'>" . $y . "</option> "; } echo "</select>"; echo "</form>"; echo "</center>"; } ?> <form action='' method='POST'> <textarea type='text' name='codecopy'> <?php dob_generate (); ?> </textarea> </form> <?php } ?> It often is so simple. Link to comment https://forums.phpfreaks.com/topic/228921-small-date-of-birth-menu-generator-i-wrote-how-to-make-code-copy-able/#findComment-1179989 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.