Solved display the result in a textbox using php?

September 9, 2011 at 18:29:49
Specs: Windows 7
i need to compute the age of the user from a drop down menu(month-day-year) and then display the result in a textbox. i have this code so far...

<?php
function checkAge()
{
$year = $_GET['byear'];
$date = Date("Y");

$age = $date - $year;
//$age must be displayed in the age textbox

}
?>

<select name="birthmonth" id = "bmonth">
<?php
$months = array("January","February","March","April",
"May","June","July","August","September",
"October","November","December");

foreach ($months as $value)
{
echo "<option value = '$value'> $value </option>";
}
?>
</select>  

<select name="birthday" id = "bday">
<?php
$counter = 1;
while($counter <= 31)
{
echo "<option value = '$counter'> $counter </option>";
$counter++;
}
?>
</select>  

<select name="byear" id = "year" onchange = "checkAge()">
<?php
for($i = 2011; $i >= 1990; $i--)
{
echo "<option value='$i'>$i</option>";
}
?>
</select>

//need to display the result here
<input type = "text" name = "age" style = "width:200px" id = "age"/>


See More: display the result in a textbox using php?

Report •


#1
September 11, 2011 at 17:03:40
✔ Best Answer
onchange = "checkAge()" would be wanting a client side script function named checkAge and not your php function.

if you want php alone, use a form; when you process it, you'll be able to output the age in the input box.

if you use client side scripting, just modify your checkAge function a bit... instead of php, maybe use javascript. you'll be able to update your "age" field without a form and pretty much keep what code you've got now.


Report •

#2
September 11, 2011 at 17:09:43
thanks shutat works fine now :)

Report •

#3
September 18, 2011 at 13:03:10
This is the first forum I've ever seen where thanking someone gets nagative feedback; what's more amusing is the "experts" not having enough courage to post a corrective reponse.

Why would anyone take this dribble seriously?

sbb24, you're quite welcome... glad to help.

--------------
oooh; how touching. maybe this will sooth the baby.


Report •

Related Solutions


Ask Question