Jump to content

Problem with drop down menu


Trium918

Recommended Posts

The dob function below populates the drop down menu, but there isn't any output being displayed to the screen. Why? Can someone tell me?

<?php
function dob() {
$month = array ("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
$select = "<select name=\"birth_month\" >\n";
$select .="<option val=\"0\">Month\n";
for ($i = 0; $i < count($month); $i++) {
$val = $i+1;
$select .= "<option val=\"".$val."\">".$month[$i]."\n"; 
}
$select .= "</option></select>";
$select .=" ";
$select .= "<select name=\"birth_day\">\n";
$select .="<option val=\"0\">Day\n";
for ($i = 0; $i < 31; $i++) {
  $val = $i+1;
  $select .= "<option val=\"".$val."\">".$val."\n"; 
}
  $select .= "</option></select>";
return $select;
}
$birth_date = dob();
echo $birth_date;

$birth_month = $_POST['birth_month'];
$birth_day = $_POST['birth_day'];

$self = $_SERVER['PHP_SELF'];
?>
<form action="<?php echo $self ?>" method="post">
<table border="1"><tr><td>
<?php
if (isset($_POST['submit'])) { 
  echo $birth_month."/".$birth_day;
}
?>
</td></tr><tr><td>
<input type="submit" value="Submit" name="submit" />
</td></tr></table>
</form>

Link to comment
https://forums.phpfreaks.com/topic/97387-problem-with-drop-down-menu/
Share on other sites

the problem is that the date <SELECT> form elements are outside of the <FORM>

 

move echo $birth_date; to inside the <FORM>

 

<?php
function dob() {
$month = array ("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
$select = "<select name=\"birth_month\" >\n";
$select .="<option val=\"0\">Month\n";
for ($i = 0; $i < count($month); $i++) {
	$val = $i+1;
	$select .= "<option val=\"".$val."\">".$month[$i]."\n"; 
}
	$select .= "</option></select>";
$select .=" ";
$select .= "<select name=\"birth_day\">\n";
$select .="<option val=\"0\">Day\n";
for ($i = 0; $i < 31; $i++) {
	$val = $i+1;
	$select .= "<option val=\"".$val."\">".$val."\n"; 
}
$select .= "</option></select>";
return $select;
}

$birth_date = dob();

$birth_month = $_POST['birth_month'];
$birth_day = $_POST['birth_day'];

$self = $_SERVER['PHP_SELF'];
?>
<form action="<?php echo $self ?>" method="post">
<?php
echo $birth_date;
?>
<table border="1"><tr><td>
<?php
if (isset($_POST['submit'])) { 
  echo $birth_month."/".$birth_day;
}
?>
</td></tr><tr><td>
<input type="submit" value="Submit" name="submit" />
</td></tr></table>
</form>

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.