Jump to content

Small Date of Birth Menu Generator I Wrote -> How to Make Code Copy-able?


chaseman

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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.