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>";
}

?>

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?

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.

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.