bob12345
bob12345

Reputation: 111

php drop down detect selection

I have a date of birth, and when the user is over Feb (02), the days should go only to 29. As you can see I'm using $month="1" just to test it. I'm supposed to use PHP only, no JavaScript or anything else. How would i go about making that?

<?php
$month="1"; // <-- currently using this to make it 29,30 or 31 days

print "<select name='day'>";
if  ($month==1){
    for ($i=0; $i<=28; $i++)    
    {
        $day = 1 + $i;
        print "<option value = $day>" . $day ."</option>";
    }
}
if  ($month==2){
    for ($i=0; $i<=29; $i++)
    {
        $day = 1 + $i;
        print "<option value = $day>" . $day ."</option>";
    }
}


print "</select>";

print "<select name='month'>";
for ($i=0; $i<=11; $i++)
{

    $month = 1 + $i;
    print "<option value = $month>" .$month ."</option>";
}
print "</select>";

?>

Upvotes: 0

Views: 253

Answers (2)

Dovydas Navickas
Dovydas Navickas

Reputation: 3591

Without Javascript it is just impossible to do.

Upvotes: 0

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324650

Once PHP sends stuff to the browser, it is done. It cannot affect the page in any way.

JavaScript, on the other hand, takes over when the browser gets the page. It CAN change the page, and it can even ask the server to do something (in which case PHP may get involved).

In other words, you cannot do what you are asking without JavaScript.

Upvotes: 3

Related Questions